* [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family
@ 2026-12-03 7:08 Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
` (16 more replies)
0 siblings, 17 replies; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
Hello everyone,
This series adds support for CC33xx which is a new family of WLAN IEEE802.11 a/b/g/n/ax
and BLE 5.4 transceivers by Texas Instruments. These devices are 20MHz single spatial stream
enabling STA (IEEE802.11ax) and AP (IEEE802.11n only) roles as well as both roles simultaneously.
Communication to the CC33xx is done via 4-bit SDIO with two extra GPIOs: Enable and Interrupt.
This driver's architecture is a soft-MAC and derivative of existing wl18xx + wlcore code [1].
It has been tested with the AM335x and AM625x evaluation kits.
Data sheet: https://www.ti.com/lit/gpn/cc3301
All code passes sparse, smatch, coccicheck and checkpatch with very few pragmatic exceptions.
Driver is split on file boundary as required by Linux-wireless wiki:
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches#new_driver
Note that I am taking over the upstream effort that was previously carried by Michael Nemanov.
https://lore.kernel.org/linux-wireless/20241107125209.1736277-1-michael.nemanov@ti.com/
Test log:
https://gist.github.com/ramesh-ramalingam/48ae3c7a2c7af45ec529ef2ee1536e36
Change log:
v6:
Majorly addresses v5 comments along with cleanups and other minor improvements.
* Use wiphy lock/work wherever possible, reduce driver mutex usage.
* tx path rework to use mac80211 iTXQs instead of driver specific queues.
* Adapt kernel friendly apis for log,alloc,free,locks
* Many cleanup related to unused code.
* Minor improvements code style fixes and improvements
v5:
* Moved all internal definitions from scan.h to scan.c
* DT bindings now describe CC3300 as the base variant. Other variants are compatible.
* Moved MODULE_DEVICE_TABLE next to device list in sdio.c
* Minor warning fixes
Link: https://lore.kernel.org/linux-wireless/20241107125209.1736277-1-michael.nemanov@ti.com/
v4:
* Fixed DT compatibility for all CC33xx variants. Improved general formatting
* Refactored sdio.c to better align with other SDIO drivers
* Removed multiple debug traces
Link: https://lore.kernel.org/linux-wireless/20241029172354.4027886-1-michael.nemanov@ti.com/
v3:
* Added missing sign-offs
* Fixed multiple warnings for memcpy overflow
* Fixed commit message and description of device-tree bindings
Link: https://lore.kernel.org/linux-wireless/20240806170018.638585-1-michael.nemanov@ti.com/
v2:
* Fixed build bug on non-ARM architectures
* Removed driver version
* Removed trivial debug traces
* Removed debug parameters for cc33xx module
* Fixed multiple type compatibility warnings
* Minor fixes
Link: https://lore.kernel.org/linux-wireless/20240609182102.2950457-1-michael.nemanov@ti.com/
v1:
* Added dt-bindings
* Removed debugfs to ease review
* Fix build issue with CONFIG_CFG80211_CERTIFICATION_ONUS
* Fix multiple build warnings found with Clang 18 and W=12
Link: https://lore.kernel.org/linux-wireless/20240521171841.884576-1-michael.nemanov@ti.com/
[1] It was considered implementing CC33xx as another user of wlcore but The
differences in HW, host interface, IRQ functionality, Rx/Tx behavior and supported features
were too significant so this was abandoned.
Michael Nemanov (17):
dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml
wifi: cc33xx: Add cc33xx.h, cc33xx_i.h
wifi: cc33xx: Add debug.h
wifi: cc33xx: Add sdio.c, io.c, io.h
wifi: cc33xx: Add cmd.c, cmd.h
wifi: cc33xx: Add acx.c, acx.h
wifi: cc33xx: Add event.c, event.h
wifi: cc33xx: Add boot.c, boot.h
wifi: cc33xx: Add main.c
wifi: cc33xx: Add rx.c, rx.h
wifi: cc33xx: Add tx.c, tx.h
wifi: cc33xx: Add init.c, init.h
wifi: cc33xx: Add scan.c, scan.h
wifi: cc33xx: Add conf.h
wifi: cc33xx: Add ps.c, ps.h
wifi: cc33xx: Add testmode.c, testmode.h
wifi: cc33xx: Add Kconfig, Makefile
.../bindings/net/wireless/ti,cc33xx.yaml | 56 +
drivers/net/wireless/ti/Kconfig | 1 +
drivers/net/wireless/ti/Makefile | 1 +
drivers/net/wireless/ti/cc33xx/Kconfig | 24 +
drivers/net/wireless/ti/cc33xx/Makefile | 19 +
drivers/net/wireless/ti/cc33xx/acx.c | 767 +++
drivers/net/wireless/ti/cc33xx/acx.h | 827 +++
drivers/net/wireless/ti/cc33xx/boot.c | 341 ++
drivers/net/wireless/ti/cc33xx/boot.h | 24 +
drivers/net/wireless/ti/cc33xx/cc33xx.h | 445 ++
drivers/net/wireless/ti/cc33xx/cc33xx_i.h | 415 ++
drivers/net/wireless/ti/cc33xx/cmd.c | 1427 +++++
drivers/net/wireless/ti/cc33xx/cmd.h | 632 +++
drivers/net/wireless/ti/cc33xx/conf.h | 1241 +++++
drivers/net/wireless/ti/cc33xx/debug.h | 70 +
drivers/net/wireless/ti/cc33xx/event.c | 313 ++
drivers/net/wireless/ti/cc33xx/event.h | 62 +
drivers/net/wireless/ti/cc33xx/init.c | 225 +
drivers/net/wireless/ti/cc33xx/init.h | 15 +
drivers/net/wireless/ti/cc33xx/io.c | 122 +
drivers/net/wireless/ti/cc33xx/io.h | 25 +
drivers/net/wireless/ti/cc33xx/main.c | 4820 +++++++++++++++++
drivers/net/wireless/ti/cc33xx/ps.c | 39 +
drivers/net/wireless/ti/cc33xx/ps.h | 14 +
drivers/net/wireless/ti/cc33xx/rx.c | 385 ++
drivers/net/wireless/ti/cc33xx/rx.h | 86 +
drivers/net/wireless/ti/cc33xx/scan.c | 842 +++
drivers/net/wireless/ti/cc33xx/scan.h | 35 +
drivers/net/wireless/ti/cc33xx/sdio.c | 515 ++
drivers/net/wireless/ti/cc33xx/testmode.c | 303 ++
drivers/net/wireless/ti/cc33xx/testmode.h | 12 +
drivers/net/wireless/ti/cc33xx/tx.c | 1133 ++++
drivers/net/wireless/ti/cc33xx/tx.h | 157 +
33 files changed, 15393 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/wireless/ti,cc33xx.yaml
create mode 100644 drivers/net/wireless/ti/cc33xx/Kconfig
create mode 100644 drivers/net/wireless/ti/cc33xx/Makefile
create mode 100644 drivers/net/wireless/ti/cc33xx/acx.c
create mode 100644 drivers/net/wireless/ti/cc33xx/acx.h
create mode 100644 drivers/net/wireless/ti/cc33xx/boot.c
create mode 100644 drivers/net/wireless/ti/cc33xx/boot.h
create mode 100644 drivers/net/wireless/ti/cc33xx/cc33xx.h
create mode 100644 drivers/net/wireless/ti/cc33xx/cc33xx_i.h
create mode 100644 drivers/net/wireless/ti/cc33xx/cmd.c
create mode 100644 drivers/net/wireless/ti/cc33xx/cmd.h
create mode 100644 drivers/net/wireless/ti/cc33xx/conf.h
create mode 100644 drivers/net/wireless/ti/cc33xx/debug.h
create mode 100644 drivers/net/wireless/ti/cc33xx/event.c
create mode 100644 drivers/net/wireless/ti/cc33xx/event.h
create mode 100644 drivers/net/wireless/ti/cc33xx/init.c
create mode 100644 drivers/net/wireless/ti/cc33xx/init.h
create mode 100644 drivers/net/wireless/ti/cc33xx/io.c
create mode 100644 drivers/net/wireless/ti/cc33xx/io.h
create mode 100644 drivers/net/wireless/ti/cc33xx/main.c
create mode 100644 drivers/net/wireless/ti/cc33xx/ps.c
create mode 100644 drivers/net/wireless/ti/cc33xx/ps.h
create mode 100644 drivers/net/wireless/ti/cc33xx/rx.c
create mode 100644 drivers/net/wireless/ti/cc33xx/rx.h
create mode 100644 drivers/net/wireless/ti/cc33xx/scan.c
create mode 100644 drivers/net/wireless/ti/cc33xx/scan.h
create mode 100644 drivers/net/wireless/ti/cc33xx/sdio.c
create mode 100644 drivers/net/wireless/ti/cc33xx/testmode.c
create mode 100644 drivers/net/wireless/ti/cc33xx/testmode.h
create mode 100644 drivers/net/wireless/ti/cc33xx/tx.c
create mode 100644 drivers/net/wireless/ti/cc33xx/tx.h
--
2.34.1
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:20 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
` (15 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
Add device-tree bindings for the CC33xx family.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
.../bindings/net/wireless/ti,cc33xx.yaml | 56 +++++++++++++++++++
1 file changed, 56 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/wireless/ti,cc33xx.yaml
diff --git a/Documentation/devicetree/bindings/net/wireless/ti,cc33xx.yaml b/Documentation/devicetree/bindings/net/wireless/ti,cc33xx.yaml
new file mode 100644
index 000000000000..cf2c9a0e87c9
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/wireless/ti,cc33xx.yaml
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/wireless/ti,cc33xx.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments CC33xx Wireless LAN Controller
+
+maintainers:
+ - Ramesh Ramalingam <r-ramalingam@ti.com>
+
+description:
+ The CC33xx is a family of IEEE 802.11ax chips from Texas Instruments.
+ These chips must be connected via SDIO and support in-band / out-of-band IRQ.
+
+properties:
+ compatible:
+ oneOf:
+ - const: ti,cc3300
+ - items:
+ - enum:
+ - ti,cc3301
+ - ti,cc3350
+ - ti,cc3351
+ - const: ti,cc3300
+
+ reg:
+ const: 2
+
+ interrupts:
+ description:
+ The out-of-band interrupt line.
+ Can be IRQ_TYPE_EDGE_RISING or IRQ_TYPE_LEVEL_HIGH.
+ If property is omitted, SDIO in-band IRQ will be used.
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ mmc {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ wifi@2 {
+ compatible = "ti,cc3300";
+ reg = <2>;
+ interrupts = <19 IRQ_TYPE_EDGE_RISING>;
+ };
+ };
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:31 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
` (14 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
These are header files with definitions common to the entire driver.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/cc33xx.h | 445 ++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/cc33xx_i.h | 415 ++++++++++++++++++++
2 files changed, 860 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/cc33xx.h
create mode 100644 drivers/net/wireless/ti/cc33xx/cc33xx_i.h
diff --git a/drivers/net/wireless/ti/cc33xx/cc33xx.h b/drivers/net/wireless/ti/cc33xx/cc33xx.h
new file mode 100644
index 000000000000..0ace1b1f557d
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/cc33xx.h
@@ -0,0 +1,445 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __CC33XX_H__
+#define __CC33XX_H__
+
+#include "cc33xx_i.h"
+#include "rx.h"
+
+/* The maximum number of Tx descriptors in all chip families */
+#define CC33XX_MAX_TX_DESCRIPTORS 32
+
+#define CC33XX_CMD_MAX_SIZE (896)
+#define CC33XX_INI_PARAM_COMMAND_SIZE (16UL)
+#define CC33XX_INI_CMD_MAX_SIZE (CC33X_CONF_SIZE + CC33XX_INI_PARAM_COMMAND_SIZE + sizeof(int))
+
+#define CC33XX_CMD_BUFFER_SIZE ((CC33XX_INI_CMD_MAX_SIZE > CC33XX_CMD_MAX_SIZE)\
+ ? CC33XX_INI_CMD_MAX_SIZE : CC33XX_CMD_MAX_SIZE)
+
+#define CC33XX_NUM_MAC_ADDRESSES 3
+
+#define CC33XX_AGGR_BUFFER_SIZE (8 * PAGE_SIZE)
+
+#define CC33XX_NUM_TX_DESCRIPTORS 32
+#define CC33XX_NUM_RX_DESCRIPTORS 32
+
+#define CC33XX_RX_BA_MAX_SESSIONS 13
+
+#define CC33XX_MAX_AP_STATIONS 16
+
+struct partial_rx_frame;
+struct core_status;
+
+struct cc33xx_stats {
+ /* raw stats dump from FW. Covers power mgmt stats */
+ void *fw_stats;
+ unsigned long fw_stats_update;
+ unsigned int retry_count;
+ unsigned int excessive_retries;
+};
+
+struct cc33xx_ant_diversity {
+ u8 diversity_enable;
+ s8 rssi_threshold;
+ u8 default_antenna;
+ u8 padding;
+};
+
+struct cc33xx_fw_versions {
+ u16 major_version;
+ u16 minor_version;
+ u16 api_version;
+ u16 build_version;
+ u8 phy_version[6];
+};
+
+struct cc33xx {
+ bool initialized;
+ struct ieee80211_hw *hw;
+ bool mac80211_registered;
+
+ struct device *dev;
+ struct platform_device *pdev;
+
+ const struct cc33xx_if_operations *if_ops;
+
+ int wakeirq;
+
+ /* Protects parts of Rx, Tx and IRQ handling.
+ * All functions postfixed with "_locked"
+ * assume this lock is held by caller.
+ */
+ struct mutex mutex;
+ /*
+ * Protects parts of cmd send function.
+ */
+ struct mutex cmd_lock;
+
+ /* Used independently from above mutex to protect short critical sections.
+ * Though many of these sections may theoretically execute in parallel, a
+ * single lock will be used for simplicity.
+ */
+ spinlock_t cc_lock;
+
+ enum cc33xx_state state;
+ bool plt;
+ enum plt_mode plt_mode;
+ u8 plt_role_id;
+ u8 fem_manuf;
+ u8 last_vif_count;
+
+ struct core_status *core_status;
+ u8 last_fw_rls_idx;
+ u8 command_result[CC33XX_CMD_MAX_SIZE];
+ u16 result_length;
+ struct partial_rx_frame partial_rx;
+
+ unsigned long flags;
+
+ struct cc33xx_fw_download *fw_download;
+
+ struct mac_address addresses[CC33XX_NUM_MAC_ADDRESSES];
+
+ unsigned long links_map[BITS_TO_LONGS(CC33XX_MAX_LINKS)];
+ unsigned long roles_map[BITS_TO_LONGS(CC33XX_MAX_ROLES)];
+ unsigned long roc_map[BITS_TO_LONGS(CC33XX_MAX_ROLES)];
+ unsigned long rate_policies_map[BITS_TO_LONGS(CC33XX_MAX_RATE_POLICIES)];
+
+ u8 session_ids[CC33XX_MAX_LINKS];
+
+ struct list_head wlvif_list;
+
+ u8 sta_count;
+ u8 ap_count;
+
+ struct cc33xx_acx_mem_map *target_mem_map;
+
+ /* Accounting for allocated / available TX blocks on HW */
+ u32 tx_blocks_available;
+ u32 tx_allocated_blocks;
+
+ /* Accounting for allocated / available Tx packets in HW */
+ u32 tx_allocated_pkts[NUM_TX_QUEUES];
+
+ /* Frames scheduled for transmission, not handled yet */
+ unsigned long queue_stop_reasons[NUM_TX_QUEUES * CC33XX_NUM_MAC_ADDRESSES];
+
+ /* Frames received, not handled yet by mac80211 */
+ struct sk_buff_head deferred_rx_queue;
+
+ /* Frames sent, not returned yet to mac80211 */
+ struct sk_buff_head deferred_tx_queue;
+
+ struct work_struct tx_work;
+ struct workqueue_struct *freezable_wq;
+
+ /*freezable wq for netstack_work*/
+ struct workqueue_struct *freezable_netstack_wq;
+
+ /* Pending TX frames */
+ unsigned long tx_frames_map[BITS_TO_LONGS(CC33XX_MAX_TX_DESCRIPTORS)];
+ struct sk_buff *tx_frames[CC33XX_MAX_TX_DESCRIPTORS];
+ int tx_frames_cnt;
+
+ /* FW Rx counter */
+ u32 rx_counter;
+
+ /* Intermediate buffer, used for packet aggregation */
+ u8 *aggr_buf;
+ u32 aggr_buf_size;
+ size_t max_transaction_len;
+
+ /* Network stack work */
+ struct work_struct netstack_work;
+
+ /* Hardware recovery work */
+ struct work_struct recovery_work;
+
+ struct work_struct irq_deferred_work;
+
+ /* Lock-less list for deferred event handling */
+ struct llist_head event_list;
+ /* The mbox event mask */
+ u32 event_mask;
+ /* events to unmask only when ap interface is up */
+ u32 ap_event_mask;
+
+ /* vif for which the scan is running */
+ struct cc33xx_vif *scan_wlvif;
+ struct cc33xx_scan scan;
+ struct wiphy_delayed_work scan_complete_work;
+
+ struct ieee80211_vif *roc_vif;
+ struct wiphy_delayed_work roc_complete_work;
+
+ struct cc33xx_vif *sched_vif;
+
+ struct cc33xx_stats stats;
+
+ /* Current chipset configuration */
+ struct cc33xx_conf_file conf;
+
+ bool enable_11a;
+
+ /* bands supported by this instance of cc33xx */
+ struct ieee80211_supported_band bands[CC33XX_NUM_BANDS];
+
+ /* wowlan trigger was configured during suspend.
+ * (currently, only "ANY" and "PATTERN" trigger is supported)
+ */
+
+ bool keep_device_power;
+
+ /* AP-mode - links indexed by HLID. The global and broadcast links
+ * are always active.
+ */
+ struct cc33xx_link links[CC33XX_MAX_LINKS];
+
+ /* number of currently active links */
+ int active_link_count;
+
+ /* Quirks of specific hardware revisions */
+ unsigned int quirks;
+
+ /* number of currently active RX BA sessions */
+ int ba_rx_session_count;
+
+ /* AP-mode - number of currently connected stations */
+ int active_sta_count;
+
+ /* HW HT (11n) capabilities */
+ struct ieee80211_sta_ht_cap ht_cap[CC33XX_NUM_BANDS];
+
+ /* RX Data filter rule state - enabled/disabled */
+ /* used in CONFIG PM AND W8 Code */
+ unsigned long rx_filter_enabled[BITS_TO_LONGS(CC33XX_MAX_RX_FILTERS)];
+
+ /* sleep auth value currently configured to FW */
+ int sleep_auth;
+
+ /*ble_enable value - 1=enabled, 0=disabled. */
+ int ble_enable;
+
+ /* parameters for joining a TWT agreement */
+ int min_wake_duration_usec;
+ int min_wake_interval_mantissa;
+ int min_wake_interval_exponent;
+ int max_wake_interval_mantissa;
+ int max_wake_interval_exponent;
+
+ /* the number of allocated MAC addresses in this chip */
+ int num_mac_addr;
+
+ /* sta role index - if 0 - wlan0 primary station interface,
+ * if 1 - wlan2 - secondary station interface
+ */
+ u8 sta_role_idx;
+
+ u16 max_cmd_size;
+
+ struct completion command_complete;
+ struct completion peer_remove_complete;
+
+ /* dynamic fw traces */
+ u32 dynamic_fw_traces;
+
+ /* buffer for sending commands to FW */
+ u8 cmd_buf[CC33XX_CMD_BUFFER_SIZE];
+
+ /* number of keys requiring extra spare mem-blocks */
+ int extra_spare_key_count;
+
+ u8 efuse_mac_address[ETH_ALEN];
+
+ u32 fuse_rom_structure_version;
+ u32 device_part_number;
+ u32 pg_version;
+ u8 disable_5g;
+ u8 disable_6g;
+
+ struct cc33xx_fw_versions fw_ver;
+
+ u8 antenna_selection;
+
+ /* burst mode cfg */
+ u8 burst_disable;
+
+ struct cc33xx_ant_diversity diversity;
+};
+
+void cc33xx_update_inconn_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cc33xx_station *wl_sta, bool in_conn);
+
+void cc33xx_irq(void *cookie);
+
+/* Quirks */
+
+/* wl127x and SPI don't support SDIO block size alignment */
+#define CC33XX_QUIRK_TX_BLOCKSIZE_ALIGN BIT(2)
+
+/* means aggregated Rx packets are aligned to a SDIO block */
+#define CC33XX_QUIRK_RX_BLOCKSIZE_ALIGN BIT(3)
+
+/* pad only the last frame in the aggregate buffer */
+#define CC33XX_QUIRK_TX_PAD_LAST_FRAME BIT(7)
+
+/* extra header space is required for TKIP */
+#define CC33XX_QUIRK_TKIP_HEADER_SPACE BIT(8)
+
+/* Some firmwares not support sched scans while connected */
+#define CC33XX_QUIRK_NO_SCHED_SCAN_WHILE_CONN BIT(9)
+
+/* separate probe response templates for one-shot and sched scans */
+#define CC33XX_QUIRK_DUAL_PROBE_TMPL BIT(10)
+
+/* The FW only support a zero session id for AP */
+#define CC33XX_QUIRK_AP_ZERO_SESSION_ID BIT(12)
+
+#define CC33XX_HW_ACCESS_ELP_CTRL_REG 0x1FFFC
+
+enum CC33XX_FRAME_FORMAT {
+ CC33XX_B_SHORT = 0,
+ CC33XX_B_LONG,
+ CC33XX_LEGACY_OFDM,
+ CC33XX_HT_MF,
+ CC33XX_HT_GF,
+ CC33XX_HE_SU,
+ CC33XX_HE_MU,
+ CC33XX_HE_SU_ER,
+ CC33XX_HE_TB,
+ CC33XX_HE_TB_NDP_FB,
+ CC33XX_VHT
+};
+
+/* CC33xx HW Common Definitions */
+
+#define CC33XX_HOST_SYNC_PATTERN 0x5C5C5C5C
+#define CC33XX_DEVICE_SYNC_PATTERN 0xABCDDCBA
+#define CC33XX_NAB_DATA_ADDR 0x0000BFF0
+#define CC33XX_NAB_CONTROL_ADDR 0x0000BFF8
+#define CC33XX_NAB_STATUS_ADDR 0x0000BFFC
+
+#define CC33XX_NAB_SEND_CMD 0x940d
+#define CC33XX_NAB_SEND_FLAGS 0x08
+#define CC33XX_INTERNAL_DESC_SIZE 200
+#define CC33XX_NAB_EXTRA_BYTES 4
+
+#define CC33XX_TX_RESULT_QUEUE_SIZE 108
+
+struct control_info_descriptor {
+ __le16 type_and_length;
+};
+
+enum control_message_type {
+ CTRL_MSG_NONE = 0,
+ CTRL_MSG_EVENT = 1,
+ CTRL_MSG_COMMND_COMPLETE = 2
+};
+
+struct core_fw_status {
+ u8 tx_result_queue_index;
+ u8 reserved1[3];
+ u8 tx_result_queue[CC33XX_TX_RESULT_QUEUE_SIZE];
+
+ /* A bitmap (where each bit represents a single HLID)
+ * to indicate PS/Active mode of the link
+ */
+ __le32 link_ps_bitmap;
+
+ /* A bitmap (where each bit represents a single HLID)
+ * to indicate if the station is in Fast mode
+ */
+ __le32 link_fast_bitmap;
+
+ /* A bitmap (where each bit represents a single HLID)
+ * to indicate if a links is suspended/about to be suspended
+ */
+ __le32 link_suspend_bitmap;
+
+ /* packet threshold for an "almost empty" AC,
+ * for Tx schedulng purposes
+ */
+ u8 tx_flow_control_ac_threshold;
+
+ /* number of packets to queue up for a link in PS */
+ u8 tx_ps_threshold;
+
+ /* number of packet to queue up for a suspended link */
+ u8 tx_suspend_threshold;
+
+ /* Should have less than this number of packets in queue of a slow
+ * link to qualify as high priority link
+ */
+ u8 tx_slow_link_prio_threshold;
+
+ /* Should have less than this number of packets in queue of a fast
+ * link to qualify as high priority link
+ */
+ u8 tx_fast_link_prio_threshold;
+
+ /* Should have less than this number of packets in queue of a slow
+ * link before we stop queuing up packets for it.
+ */
+ u8 tx_slow_stop_threshold;
+
+ /* Should have less than this number of packets in queue of a fast
+ * link before we stop queuing up packets for it.
+ */
+ u8 tx_fast_stop_threshold;
+
+ u8 reserved2;
+ /* Additional information can be added here */
+} __packed;
+
+struct core_status {
+ __le32 block_pad[28];
+ __le32 host_interrupt_status;
+ __le32 rx_status;
+ struct core_fw_status fw_info;
+ __le32 tsf;
+} __packed;
+
+struct nab_header {
+ __le32 sync_pattern;
+ __le16 opcode;
+ __le16 len;
+} __packed;
+
+/* rx_status lower bytes hold the rx byte count */
+#define RX_BYTE_COUNT_MASK 0xFFFF
+
+#define HINT_NEW_TX_RESULT 0x1
+#define HINT_COMMAND_COMPLETE 0x2
+#define HINT_ROM_LOADER_INIT_COMPLETE 0x8
+#define HINT_SECOND_LOADER_INIT_COMPLETE 0x10
+#define HINT_FW_WAKEUP_COMPLETE 0x20
+#define HINT_FW_INIT_COMPLETE 0x40
+#define HINT_GENERAL_ERROR 0x80000000
+
+#define BOOT_TIME_INTERRUPTS (\
+ HINT_ROM_LOADER_INIT_COMPLETE | \
+ HINT_SECOND_LOADER_INIT_COMPLETE | \
+ HINT_FW_WAKEUP_COMPLETE | \
+ HINT_FW_INIT_COMPLETE)
+
+struct nab_tx_header {
+ __le32 sync;
+ __le16 opcode;
+ __le16 len;
+ __le16 desc_length;
+ u8 sd;
+ u8 flags;
+} __packed;
+
+struct nab_rx_header {
+ __le32 cnys;
+ __le16 opcode;
+ __le16 len;
+ __le32 rx_desc;
+ __le32 reserved;
+} __packed;
+
+#endif /* __CC33XX_H__ */
diff --git a/drivers/net/wireless/ti/cc33xx/cc33xx_i.h b/drivers/net/wireless/ti/cc33xx/cc33xx_i.h
new file mode 100644
index 000000000000..c0d739713c2a
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/cc33xx_i.h
@@ -0,0 +1,415 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __CC33XX_I_H__
+#define __CC33XX_I_H__
+
+#include <net/mac80211.h>
+#include <linux/platform_device.h>
+
+#include "conf.h"
+
+struct cc33xx_family_data {
+ const char *name;
+ const char *cfg_name; /* cfg file */
+};
+
+#define CC33XX_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
+#define CC33XX_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
+#define CC33XX_TX_SQN_POST_RECOVERY_PADDING 0xff
+
+#define CC33XX_BUSY_WORD_LEN (sizeof(u32))
+
+#define CC33XX_DEFAULT_BEACON_INT 100
+
+#define CC33XX_MAX_ROLES 4
+#define CC33XX_INVALID_ROLE_ID 0xff
+#define CC33XX_INVALID_LINK_ID 0xff
+
+#define CC33XX_MAX_LINKS 21
+
+/* the driver supports the 2.4Ghz and 5Ghz bands */
+#define CC33XX_NUM_BANDS 2
+
+#define CC33XX_MAX_RATE_POLICIES 16
+
+/* Defined by FW as 0. Will not be freed or allocated. */
+#define CC33XX_SYSTEM_HLID 0
+
+#define CC33XX_AP_BSS_INDEX 0
+
+enum cc33xx_state {
+ CC33XX_STATE_OFF,
+ CC33XX_STATE_RESTARTING,
+ CC33XX_STATE_ON,
+};
+
+struct cc33xx;
+
+#define NUM_TX_QUEUES 4
+
+#define CC33XX_MAX_CHANNELS 64
+struct cc33xx_scan {
+ struct cfg80211_scan_request *req;
+ bool failed;
+ u8 state;
+ u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
+ size_t ssid_len;
+};
+
+struct cc33xx_if_operations {
+ void (*interface_claim)(struct device *child);
+ void (*interface_release)(struct device *child);
+ int __must_check (*read)(struct device *child, int addr, void *buf,
+ size_t len, bool fixed);
+ int __must_check (*write)(struct device *child, int addr, void *buf,
+ size_t len, bool fixed);
+ void (*reset)(struct device *child);
+ void (*init)(struct device *child);
+ int (*power)(struct device *child, bool enable);
+ void (*set_block_size)(struct device *child, unsigned int blksz);
+ size_t (*get_max_transaction_len)(struct device *child);
+ void (*set_irq_handler)(struct device *child, void *irq_handler);
+ void (*enable_irq)(struct device *child);
+ void (*disable_irq)(struct device *child);
+};
+
+struct cc33xx_platdev_data {
+ const struct cc33xx_if_operations *if_ops;
+ const struct cc33xx_family_data *family;
+ void (*irq_handler)(struct platform_device *pdev);
+ int gpio_irq_num;
+
+ bool ref_clock_xtal; /* specify whether the clock is XTAL or not */
+ bool pwr_in_suspend;
+};
+
+#define MAX_NUM_KEYS 14
+#define MAX_KEY_SIZE 32
+
+struct cc33xx_ap_key {
+ u8 id;
+ u8 key_type;
+ u8 key_size;
+ u8 key[MAX_KEY_SIZE];
+ u8 hlid;
+ u32 tx_seq_32;
+ u16 tx_seq_16;
+};
+
+enum cc33xx_flags {
+ CC33XX_FLAG_GPIO_POWER,
+ CC33XX_FLAG_TX_PENDING,
+ CC33XX_FLAG_TX_STOPPED,
+ CC33XX_FLAG_IN_ELP,
+ CC33XX_FLAG_FW_TX_BUSY,
+ CC33XX_FLAG_SUSPENDED,
+ CC33XX_FLAG_PENDING_WORK,
+ CC33XX_FLAG_SOFT_GEMINI,
+ CC33XX_FLAG_DRIVER_REMOVED,
+ CC33XX_FLAG_RECOVERY_IN_PROGRESS,
+ CC33XX_FLAG_VIF_CHANGE_IN_PROGRESS,
+ CC33XX_FLAG_IO_FAILED,
+ CC33XX_FLAG_REINIT_TX_WDOG,
+};
+
+enum cc33xx_vif_flags {
+ WLVIF_FLAG_INITIALIZED,
+ WLVIF_FLAG_STA_ASSOCIATED,
+ WLVIF_FLAG_STA_AUTHORIZED,
+ WLVIF_FLAG_AP_STARTED,
+ WLVIF_FLAG_IN_PS,
+ WLVIF_FLAG_STA_STATE_SENT,
+ WLVIF_FLAG_PSPOLL_FAILURE,
+ WLVIF_FLAG_CS_PROGRESS,
+ WLVIF_FLAG_AP_PROBE_RESP_SET,
+ WLVIF_FLAG_IN_USE,
+ WLVIF_FLAG_ACTIVE,
+ WLVIF_FLAG_BEACON_DISABLED,
+};
+
+struct cc33xx_vif;
+
+struct cc33xx_link {
+ /* TX pending packets */
+ struct sk_buff_head tx_pending;
+
+ /* accounting for allocated / freed packets in FW */
+ u8 allocated_pkts;
+ u8 prev_freed_pkts;
+
+ u8 addr[ETH_ALEN];
+
+ /* bitmap of TIDs where RX BA sessions are active for this link */
+ u8 ba_bitmap;
+
+ /* the last fw rate index we used for this link */
+ u8 fw_rate_idx;
+
+ /* the last fw rate [Mbps] we used for this link */
+ u8 fw_rate_mbps;
+
+ /* The wlvif this link belongs to. Might be null for global links */
+ struct cc33xx_vif *wlvif;
+
+ /* total freed FW packets on the link - used for tracking the
+ * AES/TKIP PN across recoveries. Re-initialized each time
+ * from the cc33xx_station structure.
+ */
+ u64 total_freed_pkts;
+};
+
+#define CC33XX_MAX_RX_FILTERS 5
+#define CC33XX_RX_FILTER_MAX_FIELDS 8
+#define CC33XX_RX_FILTER_FLAG_IP_HEADER 0
+#define CC33XX_RX_FILTER_FLAG_ETHERNET_HEADER BIT(1)
+
+#define RX_FILTER_MAX_FIELDS_SIZE 95
+#define RX_FILTER_FIELD_OVERHEAD \
+ (sizeof(struct cc33xx_rx_filter_field) - sizeof(u8 *))
+#define RX_FILTER_MAX_PATTERN_SIZE \
+ (RX_FILTER_MAX_FIELDS_SIZE - RX_FILTER_FIELD_OVERHEAD)
+
+struct ieee80211_header {
+ __le16 frame_ctl;
+ __le16 duration_id;
+ u8 da[ETH_ALEN];
+ u8 sa[ETH_ALEN];
+ u8 bssid[ETH_ALEN];
+ __le16 seq_ctl;
+ u8 payload[];
+} __packed;
+
+enum rx_filter_action {
+ FILTER_DROP = 0,
+ FILTER_SIGNAL = 1,
+ FILTER_FW_HANDLE = 2
+};
+
+enum plt_mode {
+ PLT_OFF = 0,
+ PLT_ON = 1,
+ PLT_FEM_DETECT = 2,
+ PLT_CHIP_AWAKE = 3
+};
+
+struct cc33xx_rx_filter_field {
+ __le16 offset;
+ u8 len;
+ u8 flags;
+ u8 *pattern;
+} __packed;
+
+struct cc33xx_rx_filter {
+ u8 action;
+ int num_fields;
+ struct cc33xx_rx_filter_field fields[CC33XX_RX_FILTER_MAX_FIELDS];
+};
+
+struct cc33xx_station {
+ u8 hlid;
+ bool in_connection;
+
+ /* total freed FW packets on the link to the STA - used for tracking the
+ * AES/TKIP PN across recoveries. Re-initialized each time from the
+ * cc33xx_station structure.
+ * Used in both AP and STA mode.
+ */
+ u64 total_freed_pkts;
+};
+
+struct cc33xx_vif {
+ struct cc33xx *cc;
+ struct list_head list;
+ unsigned long flags;
+ u8 bss_type;
+ u8 p2p; /* we are using p2p role */
+ u8 role_id;
+
+ /* sta specific */
+ u8 dev_role_id;
+ u8 dev_hlid;
+
+ union {
+ struct {
+ u8 hlid;
+
+ u8 basic_rate_idx;
+ u8 ap_rate_idx;
+ u8 p2p_rate_idx;
+
+ bool qos;
+ /* channel type we started the STA role with */
+ enum nl80211_channel_type role_chan_type;
+ } sta;
+ struct {
+ u8 global_hlid;
+ u8 bcast_hlid;
+
+ /* HLIDs bitmap of associated stations */
+ unsigned long sta_hlid_map[BITS_TO_LONGS(CC33XX_MAX_LINKS)];
+
+ /* recoreded keys - set here before AP startup */
+ struct cc33xx_ap_key *recorded_keys[MAX_NUM_KEYS];
+
+ u8 mgmt_rate_idx;
+ u8 bcast_rate_idx;
+ u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
+ } ap;
+ };
+
+ unsigned long links_map[BITS_TO_LONGS(CC33XX_MAX_LINKS)];
+
+ u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
+ u8 ssid_len;
+
+ /* The current band */
+ enum nl80211_band band;
+ int channel;
+ enum nl80211_channel_type channel_type;
+
+ u32 bitrate_masks[CC33XX_NUM_BANDS];
+ u32 basic_rate_set;
+
+ /* currently configured rate set:
+ * bits 0-15 - 802.11abg rates
+ * bits 16-23 - 802.11n MCS index mask
+ * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
+ */
+ u32 basic_rate;
+ u32 rate_set;
+
+ /* probe-req template for the current AP */
+ struct sk_buff *probereq;
+
+ /* Beaconing interval (needed for ad-hoc) */
+ u32 beacon_int;
+
+ /* Default key (for WEP) */
+ u32 default_key;
+
+ /* Our association ID */
+ u16 aid;
+
+ /* retry counter for PSM entries */
+ u8 psm_entry_retry;
+
+ /* in dBm */
+ int power_level;
+
+ int rssi_thold;
+ int last_rssi_event;
+
+ /* save the current encryption type for auto-arp config */
+ u8 encryption_type;
+
+ /* RX BA constraint value */
+ bool ba_support;
+ bool ba_allowed;
+
+ bool wmm_enabled;
+
+ struct wiphy_delayed_work channel_switch_work;
+ struct wiphy_delayed_work connection_loss_work;
+
+ /* number of in connection stations */
+ int inconn_count;
+
+ /* This vif's queues are mapped to mac80211 HW queues as:
+ * VO - hw_queue_base
+ * VI - hw_queue_base + 1
+ * BE - hw_queue_base + 2
+ * BK - hw_queue_base + 3
+ */
+ int hw_queue_base;
+
+ struct wiphy_delayed_work roc_timeout_work;
+
+ /* total freed FW packets on the link.
+ * For STA this holds the PN of the link to the AP.
+ * For AP this holds the PN of the broadcast link.
+ */
+ u64 total_freed_pkts;
+
+ /* for MBSSID: this BSS is a nontransmitted BSS profile
+ * Relevant for STA role
+ */
+ bool nontransmitted;
+
+ /* for MBSSID: update transmitter BSSID */
+ u8 transmitter_bssid[ETH_ALEN];
+
+ /* for MBSSID: BSSID index */
+ u8 bssid_index;
+
+ /* for MBSSID: BSSID indicator */
+ u8 bssid_indicator;
+
+ /* for STA: if connection established and has HE support*/
+ u8 sta_has_he;
+
+ /* This struct must be last!
+ * data that has to be saved acrossed reconfigs (e.g. recovery)
+ * should be declared in this struct.
+ */
+ u8 persistent[];
+};
+
+static inline struct cc33xx_vif *cc33xx_vif_to_data(struct ieee80211_vif *vif)
+{
+ return (struct cc33xx_vif *)vif->drv_priv;
+}
+
+static inline
+struct ieee80211_vif *cc33xx_wlvif_to_vif(struct cc33xx_vif *wlvif)
+{
+ return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
+}
+
+static inline bool cc33xx_is_p2p_mgmt(struct cc33xx_vif *wlvif)
+{
+ return cc33xx_wlvif_to_vif(wlvif)->type == NL80211_IFTYPE_P2P_DEVICE;
+}
+
+#define cc33xx_for_each_wlvif(cc, wlvif) \
+ list_for_each_entry(wlvif, &(cc)->wlvif_list, list)
+
+#define cc33xx_for_each_wlvif_continue(cc, wlvif) \
+ list_for_each_entry_continue(wlvif, &(cc)->wlvif_list, list)
+
+#define cc33xx_for_each_wlvif_bss_type(cc, wlvif, _bss_type) \
+ cc33xx_for_each_wlvif((cc), (wlvif)) \
+ if ((wlvif)->bss_type == (_bss_type))
+
+#define cc33xx_for_each_wlvif_sta(cc, wlvif) \
+ cc33xx_for_each_wlvif_bss_type(cc, wlvif, BSS_TYPE_STA_BSS)
+
+#define cc33xx_for_each_wlvif_ap(cc, wlvif) \
+ cc33xx_for_each_wlvif_bss_type(cc, wlvif, BSS_TYPE_AP_BSS)
+
+int cc33xx_plt_start(struct cc33xx *cc, const enum plt_mode plt_mode);
+int cc33xx_plt_stop(struct cc33xx *cc);
+void cc33xx_queue_recovery_work(struct cc33xx *cc);
+void cc33xx_flush_deferred_work(struct cc33xx *cc);
+
+#define CC33XX_MAX_TXPWR 21 /* maximum power limit is 21dBm */
+#define CC33XX_MIN_TXPWR -10 /* minimum power limit is -10dBm */
+
+#define CC33XX_TX_QUEUE_LOW_WATERMARK 32
+#define CC33XX_TX_QUEUE_HIGH_WATERMARK 256
+
+#define CC33XX_RX_QUEUE_MAX_LEN 256
+
+/* cc33xx needs a 200ms sleep after power on, and a 20ms sleep before power
+ * on in case is has been shut down shortly before
+ */
+#define CC33XX_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
+#define CC33XX_POWER_ON_SLEEP 200 /* in milliseconds */
+
+/* Macros to handle cc33xx.sta_rate_set */
+#define HW_HT_RATES_OFFSET 16
+#define HW_MIMO_RATES_OFFSET 24
+
+#endif /* __CC33XX_I_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 03/17] wifi: cc33xx: Add debug.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:26 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
` (13 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
These are trace macros used throughout the driver.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/debug.h | 70 ++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/debug.h
diff --git a/drivers/net/wireless/ti/cc33xx/debug.h b/drivers/net/wireless/ti/cc33xx/debug.h
new file mode 100644
index 000000000000..0f47942d4ecb
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/debug.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+#define DRIVER_NAME "cc33xx"
+#define DRIVER_PREFIX DRIVER_NAME ": "
+
+enum {
+ DEBUG_NONE = 0,
+ DEBUG_IRQ = BIT(0),
+ DEBUG_SPI = BIT(1),
+ DEBUG_BOOT = BIT(2),
+ DEBUG_CORE_STATUS = BIT(3),
+ DEBUG_TESTMODE = BIT(4),
+ DEBUG_EVENT = BIT(5),
+ DEBUG_TX = BIT(6),
+ DEBUG_RX = BIT(7),
+ DEBUG_SCAN = BIT(8),
+ DEBUG_CRYPT = BIT(9),
+ DEBUG_PSM = BIT(10),
+ DEBUG_MAC80211 = BIT(11),
+ DEBUG_CMD = BIT(12),
+ DEBUG_ACX = BIT(13),
+ DEBUG_SDIO = BIT(14),
+ DEBUG_FILTERS = BIT(15),
+ DEBUG_ADHOC = BIT(16),
+ DEBUG_AP = BIT(17),
+ DEBUG_PROBE = BIT(18),
+ DEBUG_IO = BIT(19),
+ DEBUG_MASTER = DEBUG_AP,
+ DEBUG_CC33XX = BIT(20),
+ DEBUG_ALL = GENMASK(31, 0),
+ DEBUG_NO_DATAPATH = (DEBUG_ALL & ~DEBUG_IRQ & ~DEBUG_TX & ~DEBUG_RX & ~DEBUG_CORE_STATUS),
+};
+
+extern u32 cc33xx_debug_level;
+
+#define DEBUG_DUMP_LIMIT 1024
+
+#define cc33xx_debug(dev, level, fmt, arg...) \
+ do { \
+ if (unlikely((level) & cc33xx_debug_level)) \
+ dev_dbg(dev, fmt, ##arg); \
+ } while (0)
+
+#define cc33xx_dump(level, prefix, buf, len) \
+ do { \
+ if ((level) & cc33xx_debug_level) \
+ print_hex_dump_debug(DRIVER_PREFIX prefix, \
+ DUMP_PREFIX_OFFSET, 16, 1, \
+ buf, \
+ min_t(size_t, len, DEBUG_DUMP_LIMIT), \
+ 0); \
+ } while (0)
+
+#define cc33xx_dump_ascii(level, prefix, buf, len) \
+ do { \
+ if ((level) & cc33xx_debug_level) \
+ print_hex_dump_debug(DRIVER_PREFIX prefix, \
+ DUMP_PREFIX_OFFSET, 16, 1, \
+ buf, \
+ min_t(size_t, len, DEBUG_DUMP_LIMIT), \
+ true); \
+ } while (0)
+
+#endif /* __DEBUG_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (2 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:33 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
` (12 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
sdio.c implements SDIO transport functions. These are bound into
struct cc33xx_if_operations and accessed via io.h in order to abstract
multiple transport interfaces such as SPI in the future.
The CC33xx driver supports the SDIO in-band IRQ option so the IRQ from
the device received here as well.
Unlike wl1xxx products, there is no longer mapping between
HW and SDIO / SPI address space of any kind.
There are only 3 valid addresses for control, data and status
transactions each with a predefined structure.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/io.c | 122 ++++++
drivers/net/wireless/ti/cc33xx/io.h | 25 ++
drivers/net/wireless/ti/cc33xx/sdio.c | 515 ++++++++++++++++++++++++++
3 files changed, 662 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/io.c
create mode 100644 drivers/net/wireless/ti/cc33xx/io.h
create mode 100644 drivers/net/wireless/ti/cc33xx/sdio.c
diff --git a/drivers/net/wireless/ti/cc33xx/io.c b/drivers/net/wireless/ti/cc33xx/io.c
new file mode 100644
index 000000000000..c79148b0e97c
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/io.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "cc33xx.h"
+#include "debug.h"
+#include "io.h"
+#include "tx.h"
+
+bool cc33xx_set_block_size(struct cc33xx *cc)
+{
+ if (cc->if_ops->set_block_size) {
+ cc->if_ops->set_block_size(cc->dev, CC33XX_BUS_BLOCK_SIZE);
+ cc33xx_debug(cc->dev, DEBUG_CC33XX,
+ "Set BLKsize to %d\n", CC33XX_BUS_BLOCK_SIZE);
+ return true;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_CC33XX, "Could not set BLKsize\n");
+ return false;
+}
+
+void cc33xx_disable_interrupts_nosync(struct cc33xx *cc)
+{
+ cc->if_ops->disable_irq(cc->dev);
+}
+
+void cc33xx_enable_interrupts(struct cc33xx *cc)
+{
+ cc->if_ops->enable_irq(cc->dev);
+
+ cc33xx_irq(cc);
+}
+
+void cc33xx_io_reset(struct cc33xx *cc)
+{
+ if (cc->if_ops->reset)
+ cc->if_ops->reset(cc->dev);
+}
+
+void cc33xx_io_init(struct cc33xx *cc)
+{
+ if (cc->if_ops->init)
+ cc->if_ops->init(cc->dev);
+}
+
+/* Raw target IO, address is not translated */
+int __must_check cc33xx_raw_write(struct cc33xx *cc, int addr,
+ void *buf, size_t len, bool fixed)
+{
+ int ret;
+
+ if (test_bit(CC33XX_FLAG_IO_FAILED, &cc->flags) ||
+ WARN_ON((test_bit(CC33XX_FLAG_IN_ELP, &cc->flags) &&
+ addr != CC33XX_HW_ACCESS_ELP_CTRL_REG)))
+ return -EIO;
+
+ ret = cc->if_ops->write(cc->dev, addr, buf, len, fixed);
+ if (ret && cc->state != CC33XX_STATE_OFF)
+ set_bit(CC33XX_FLAG_IO_FAILED, &cc->flags);
+
+ return ret;
+}
+
+int __must_check cc33xx_raw_read(struct cc33xx *cc, int addr,
+ void *buf, size_t len, bool fixed)
+{
+ int ret;
+
+ if (test_bit(CC33XX_FLAG_IO_FAILED, &cc->flags) ||
+ WARN_ON((test_bit(CC33XX_FLAG_IN_ELP, &cc->flags) &&
+ addr != CC33XX_HW_ACCESS_ELP_CTRL_REG)))
+ return -EIO;
+
+ ret = cc->if_ops->read(cc->dev, addr, buf, len, fixed);
+ if (ret && cc->state != CC33XX_STATE_OFF)
+ set_bit(CC33XX_FLAG_IO_FAILED, &cc->flags);
+
+ return ret;
+}
+
+void claim_core_status_lock(struct cc33xx *cc)
+{
+ /* When accessing core-status data (read or write) the transport lock
+ * should be held.
+ */
+ cc->if_ops->interface_claim(cc->dev);
+}
+
+void release_core_status_lock(struct cc33xx *cc)
+{
+ /* After accessing core-status data (read or write) the transport lock
+ * should be released.
+ */
+ cc->if_ops->interface_release(cc->dev);
+}
+
+void cc33xx_power_off(struct cc33xx *cc)
+{
+ int ret = 0;
+
+ if (!test_bit(CC33XX_FLAG_GPIO_POWER, &cc->flags))
+ return;
+
+ if (cc->if_ops->power)
+ ret = cc->if_ops->power(cc->dev, false);
+ if (!ret)
+ clear_bit(CC33XX_FLAG_GPIO_POWER, &cc->flags);
+}
+
+int cc33xx_power_on(struct cc33xx *cc)
+{
+ int ret = 0;
+
+ if (cc->if_ops->power)
+ ret = cc->if_ops->power(cc->dev, true);
+ if (ret == 0)
+ set_bit(CC33XX_FLAG_GPIO_POWER, &cc->flags);
+
+ return ret;
+}
diff --git a/drivers/net/wireless/ti/cc33xx/io.h b/drivers/net/wireless/ti/cc33xx/io.h
new file mode 100644
index 000000000000..35f6d4b483a6
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/io.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __IO_H__
+#define __IO_H__
+
+struct cc33xx;
+
+void cc33xx_disable_interrupts_nosync(struct cc33xx *cc);
+void cc33xx_enable_interrupts(struct cc33xx *cc);
+void cc33xx_io_reset(struct cc33xx *cc);
+void cc33xx_io_init(struct cc33xx *cc);
+int __must_check cc33xx_raw_read(struct cc33xx *cc, int addr,
+ void *buf, size_t len, bool fixed);
+int __must_check cc33xx_raw_write(struct cc33xx *cc, int addr,
+ void *buf, size_t len, bool fixed);
+void claim_core_status_lock(struct cc33xx *cc);
+void release_core_status_lock(struct cc33xx *cc);
+void cc33xx_power_off(struct cc33xx *cc);
+int cc33xx_power_on(struct cc33xx *cc);
+bool cc33xx_set_block_size(struct cc33xx *cc);
+
+#endif /* __IO_H__ */
diff --git a/drivers/net/wireless/ti/cc33xx/sdio.c b/drivers/net/wireless/ti/cc33xx/sdio.c
new file mode 100644
index 000000000000..5edbe1ebc7a8
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/sdio.c
@@ -0,0 +1,515 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include <linux/mmc/sdio_func.h>
+#include <linux/mmc/host.h>
+#include <linux/gpio.h>
+#include <linux/pm_runtime.h>
+#include <linux/of_irq.h>
+
+#include "cc33xx.h"
+#include "io.h"
+
+#ifndef SDIO_VENDOR_ID_TI
+#define SDIO_VENDOR_ID_TI 0x0097
+#endif
+
+#define SDIO_DEVICE_ID_CC33XX_NO_EFUSE 0x4076
+#define SDIO_DEVICE_ID_TI_CC33XX 0x4077
+
+struct cc33xx_sdio_glue {
+ struct device *dev;
+ struct platform_device *core;
+};
+
+static void cc33xx_sdio_claim(struct device *child)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_claim_host(func);
+}
+
+static void cc33xx_sdio_release(struct device *child)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_release_host(func);
+}
+
+static void cc33xx_sdio_set_block_size(struct device *child,
+ unsigned int blksz)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_claim_host(func);
+ sdio_set_block_size(func, blksz);
+ sdio_release_host(func);
+}
+
+static int __must_check cc33xx_sdio_raw_read(struct device *child, int addr,
+ void *buf, size_t len, bool fixed)
+{
+ int ret;
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_claim_host(func);
+
+ if (unlikely(addr == CC33XX_HW_ACCESS_ELP_CTRL_REG)) {
+ ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
+ dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
+ addr, ((u8 *)buf)[0]);
+ } else {
+ if (fixed)
+ ret = sdio_readsb(func, buf, addr, len);
+ else
+ ret = sdio_memcpy_fromio(func, buf, addr, len);
+
+ dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
+ addr, len);
+ }
+
+ sdio_release_host(func);
+
+ if (ret)
+ dev_err(child->parent, "sdio read failed (%d)\n", ret);
+
+ return ret;
+}
+
+static int __must_check cc33xx_sdio_raw_write(struct device *child, int addr,
+ void *buf, size_t len, bool fixed)
+{
+ int ret;
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_claim_host(func);
+
+ if (unlikely(addr == CC33XX_HW_ACCESS_ELP_CTRL_REG)) {
+ sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
+ } else {
+ if (fixed)
+ ret = sdio_writesb(func, addr, buf, len);
+ else
+ ret = sdio_memcpy_toio(func, addr, buf, len);
+ }
+
+ sdio_release_host(func);
+
+ if (ret)
+ dev_err(child->parent, "sdio write failed (%d)\n", ret);
+
+ return ret;
+}
+
+static int cc33xx_sdio_power_on(struct cc33xx_sdio_glue *glue)
+{
+ int ret;
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+ struct mmc_card *card = func->card;
+
+ ret = pm_runtime_get_sync(&card->dev);
+ if (ret < 0) {
+ pm_runtime_put_noidle(&card->dev);
+ dev_err(glue->dev, "%s: failed to get_sync(%d)\n",
+ __func__, ret);
+
+ return ret;
+ }
+
+ sdio_claim_host(func);
+ ret = sdio_enable_func(func);
+ sdio_release_host(func);
+
+ return ret;
+}
+
+static int cc33xx_sdio_power_off(struct cc33xx_sdio_glue *glue)
+{
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+ struct mmc_card *card = func->card;
+
+ sdio_claim_host(func);
+ sdio_disable_func(func);
+ sdio_release_host(func);
+
+ /* Let runtime PM know the card is powered off */
+ pm_runtime_put(&card->dev);
+ return 0;
+}
+
+static int cc33xx_sdio_set_power(struct device *child, bool enable)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+
+ if (enable)
+ return cc33xx_sdio_power_on(glue);
+ else
+ return cc33xx_sdio_power_off(glue);
+}
+
+/**
+ * inband_irq_handler - Called from the MMC subsystem when the
+ * function's IRQ is signaled.
+ * @func: an SDIO function of the card
+ *
+ * Note that the host is already claimed when handler is invoked.
+ */
+static void inband_irq_handler(struct sdio_func *func)
+{
+ struct cc33xx_sdio_glue *glue = sdio_get_drvdata(func);
+ struct platform_device *pdev = glue->core;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ if (WARN_ON(!pdev_data->irq_handler))
+ return;
+
+ pdev_data->irq_handler(pdev);
+}
+
+static void cc33xx_enable_async_interrupt(struct sdio_func *func)
+{
+ u8 reg_val;
+ const int CCCR_REG_16_ADDR = 0x16;
+ const int ENABLE_ASYNC_IRQ_BIT = BIT(1);
+
+ reg_val = sdio_f0_readb(func, CCCR_REG_16_ADDR, NULL);
+ reg_val |= ENABLE_ASYNC_IRQ_BIT;
+ sdio_f0_writeb(func, reg_val, CCCR_REG_16_ADDR, NULL);
+}
+
+static void cc33xx_sdio_enable_irq(struct device *child)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_claim_host(func);
+ cc33xx_enable_async_interrupt(func);
+ sdio_claim_irq(func, inband_irq_handler);
+ sdio_release_host(func);
+}
+
+static void cc33xx_sdio_disable_irq(struct device *child)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+ sdio_claim_host(func);
+ sdio_release_irq(func);
+ sdio_release_host(func);
+}
+
+static void cc33xx_enable_line_irq(struct device *child)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct platform_device *pdev = glue->core;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ enable_irq(pdev_data->gpio_irq_num);
+}
+
+static void cc33xx_disable_line_irq(struct device *child)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct platform_device *pdev = glue->core;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ disable_irq_nosync(pdev_data->gpio_irq_num);
+}
+
+static void cc33xx_set_irq_handler(struct device *child, void *handler)
+{
+ struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+ struct platform_device *pdev = glue->core;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ pdev_data->irq_handler = handler;
+}
+
+static const struct cc33xx_if_operations sdio_ops_gpio_irq = {
+ .interface_claim = cc33xx_sdio_claim,
+ .interface_release = cc33xx_sdio_release,
+ .read = cc33xx_sdio_raw_read,
+ .write = cc33xx_sdio_raw_write,
+ .power = cc33xx_sdio_set_power,
+ .set_block_size = cc33xx_sdio_set_block_size,
+ .set_irq_handler = cc33xx_set_irq_handler,
+ .disable_irq = cc33xx_disable_line_irq,
+ .enable_irq = cc33xx_enable_line_irq,
+};
+
+static const struct cc33xx_if_operations sdio_ops_inband_irq = {
+ .interface_claim = cc33xx_sdio_claim,
+ .interface_release = cc33xx_sdio_release,
+ .read = cc33xx_sdio_raw_read,
+ .write = cc33xx_sdio_raw_write,
+ .power = cc33xx_sdio_set_power,
+ .set_block_size = cc33xx_sdio_set_block_size,
+ .set_irq_handler = cc33xx_set_irq_handler,
+ .disable_irq = cc33xx_sdio_disable_irq,
+ .enable_irq = cc33xx_sdio_enable_irq,
+};
+
+static const struct cc33xx_family_data cc33xx_data = {
+ .name = "cc33xx",
+ .cfg_name = "ti-connectivity/cc33xx-conf.bin",
+};
+
+static const struct of_device_id cc33xx_sdio_of_match_table[] = {
+ { .compatible = "ti,cc3300", .data = &cc33xx_data },
+ { }
+};
+
+static int cc33xx_probe_of(struct device *dev, int *irq, int *wakeirq,
+ struct cc33xx_platdev_data *pdev_data)
+{
+ struct device_node *np = dev->of_node;
+ const struct of_device_id *of_id;
+
+ of_id = of_match_node(cc33xx_sdio_of_match_table, np);
+ if (!of_id)
+ return -ENODEV;
+
+ pdev_data->family = of_id->data;
+
+ *irq = irq_of_parse_and_map(np, 0);
+
+ *wakeirq = irq_of_parse_and_map(np, 1);
+
+ return 0;
+}
+
+static irqreturn_t gpio_irq_hard_handler(int irq, void *cookie)
+{
+ return IRQ_WAKE_THREAD;
+}
+
+static irqreturn_t gpio_irq_thread_handler(int irq, void *cookie)
+{
+ struct sdio_func *func = cookie;
+ struct cc33xx_sdio_glue *glue = sdio_get_drvdata(func);
+ struct platform_device *pdev = glue->core;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ if (WARN_ON(!pdev_data->irq_handler))
+ return IRQ_HANDLED;
+
+ pdev_data->irq_handler(pdev);
+
+ return IRQ_HANDLED;
+}
+
+static int sdio_cc33xx_probe(struct sdio_func *func,
+ const struct sdio_device_id *id)
+{
+ struct cc33xx_platdev_data *pdev_data;
+ struct cc33xx_sdio_glue *glue;
+ struct resource res[1];
+ mmc_pm_flag_t mmcflags;
+ int ret = -ENOMEM;
+ int gpio_irq, wakeirq, irq_flags;
+
+ /* We are only able to handle the wlan function */
+ if (func->num != 0x02)
+ return -ENODEV;
+
+ pdev_data = devm_kzalloc_obj(&func->dev, *pdev_data);
+ if (!pdev_data)
+ return -ENOMEM;
+
+ glue = devm_kzalloc_obj(&func->dev, *glue);
+ if (!glue)
+ return -ENOMEM;
+
+ glue->dev = &func->dev;
+
+ /* Grab access to FN0 for ELP reg. */
+ func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
+
+ /* Use block mode for transferring over one block size of data */
+ func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
+
+ ret = cc33xx_probe_of(&func->dev, &gpio_irq, &wakeirq, pdev_data);
+ if (ret)
+ return ret;
+
+ /* if sdio can keep power while host is suspended, enable wow */
+ mmcflags = sdio_get_host_pm_caps(func);
+
+ sdio_set_drvdata(func, glue);
+
+ /* Tell PM core that we don't need the card to be powered now */
+ pm_runtime_put_noidle(&func->dev);
+
+ glue->core = platform_device_alloc("cc33xx", PLATFORM_DEVID_AUTO);
+ if (!glue->core) {
+ dev_err(glue->dev, "can't allocate platform_device\n");
+ return -ENOMEM;
+ }
+
+ glue->core->dev.parent = &func->dev;
+
+ if (gpio_irq) {
+ irq_flags = irqd_get_trigger_type(irq_get_irq_data(gpio_irq));
+
+ irq_set_status_flags(gpio_irq, IRQ_NOAUTOEN);
+
+ if (irq_flags & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW))
+ irq_flags |= IRQF_ONESHOT;
+
+ ret = request_threaded_irq(gpio_irq, gpio_irq_hard_handler,
+ gpio_irq_thread_handler,
+ irq_flags, glue->core->name, func);
+ if (ret) {
+ dev_err(glue->dev, "can't register GPIO IRQ handler\n");
+ goto out_dev_put;
+ }
+
+ pdev_data->gpio_irq_num = gpio_irq;
+
+ if ((mmcflags & MMC_PM_KEEP_POWER) &&
+ (enable_irq_wake(gpio_irq) == 0))
+ pdev_data->pwr_in_suspend = true;
+
+ pdev_data->if_ops = &sdio_ops_gpio_irq;
+ } else {
+ pdev_data->if_ops = &sdio_ops_inband_irq;
+ }
+
+ if (wakeirq > 0) {
+ res[0].start = wakeirq;
+ res[0].flags = IORESOURCE_IRQ |
+ irqd_get_trigger_type(irq_get_irq_data(wakeirq));
+ res[0].name = "wakeirq";
+
+ ret = platform_device_add_resources(glue->core, res, 1);
+ if (ret) {
+ dev_err(glue->dev, "can't add resources\n");
+ goto out_dev_put;
+ }
+ }
+
+ ret = platform_device_add_data(glue->core, pdev_data,
+ sizeof(*pdev_data));
+ if (ret) {
+ dev_err(glue->dev, "can't add platform data\n");
+ goto out_dev_put;
+ }
+
+ ret = platform_device_add(glue->core);
+ if (ret) {
+ dev_err(glue->dev, "can't add platform device\n");
+ goto out_dev_put;
+ }
+ return 0;
+
+out_dev_put:
+ platform_device_put(glue->core);
+
+ if (pdev_data->gpio_irq_num)
+ free_irq(pdev_data->gpio_irq_num, func);
+
+ return ret;
+}
+
+static void sdio_cc33xx_remove(struct sdio_func *func)
+{
+ struct cc33xx_sdio_glue *glue = sdio_get_drvdata(func);
+ struct platform_device *pdev = glue->core;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ int gpio_irq_num = pdev_data->gpio_irq_num;
+ bool pwr_in_suspend = pdev_data->pwr_in_suspend;
+
+ /* Undo decrement done above in sdio_cc33xx_probe */
+ pm_runtime_get_noresume(&func->dev);
+
+ /* Do not use pdev_data after this point */
+ platform_device_unregister(glue->core);
+
+ if (gpio_irq_num) {
+ free_irq(gpio_irq_num, func);
+ if (pwr_in_suspend)
+ disable_irq_wake(gpio_irq_num);
+ } else {
+ sdio_claim_host(func);
+ sdio_release_irq(func);
+ sdio_release_host(func);
+ }
+}
+
+static int __maybe_unused cc33xx_suspend(struct device *dev)
+{
+ /* Tell MMC/SDIO core it's OK to power down the card
+ * (if it isn't already), but not to remove it completely
+ */
+ struct sdio_func *func = dev_to_sdio_func(dev);
+ struct cc33xx_sdio_glue *glue = sdio_get_drvdata(func);
+ struct cc33xx *cc = platform_get_drvdata(glue->core);
+ mmc_pm_flag_t sdio_flags;
+ int ret = 0;
+
+ if (!cc) {
+ dev_err(dev, "no cc33xx module was probed\n");
+ return -EINVAL;
+ }
+
+ dev_dbg(dev, "cc33xx suspend. keep_device_power: %d\n",
+ cc->keep_device_power);
+
+ if (cc->keep_device_power) {
+ sdio_flags = sdio_get_host_pm_caps(func);
+
+ if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
+ dev_err(dev, "can't keep power while host is suspended\n");
+ return -EINVAL;
+ }
+
+ /* keep power while host suspended */
+ ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
+ if (ret) {
+ dev_err(dev, "error while trying to keep power\n");
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+static int __maybe_unused cc33xx_resume(struct device *dev)
+{
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(cc33xx_sdio_pm_ops, cc33xx_suspend, cc33xx_resume);
+
+static const struct sdio_device_id cc33xx_devices[] = {
+ { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_CC33XX) },
+ { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_CC33XX_NO_EFUSE) },
+ {}
+};
+
+MODULE_DEVICE_TABLE(sdio, cc33xx_devices);
+
+static struct sdio_driver cc33xx_sdio_driver = {
+ .name = "cc33xx_sdio",
+ .id_table = cc33xx_devices,
+ .probe = sdio_cc33xx_probe,
+ .remove = sdio_cc33xx_remove,
+ .drv = {
+ .pm = pm_sleep_ptr(&cc33xx_sdio_pm_ops),
+ },
+};
+
+module_sdio_driver(cc33xx_sdio_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SDIO transport for Texas Instruments CC33xx WLAN driver");
+MODULE_AUTHOR("Michael Nemanov <michael.nemanov@ti.com>");
+MODULE_AUTHOR("Sabeeh Khan <sabeeh-khan@ti.com>");
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (3 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:42 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
` (11 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
This is the command infrastructure for the CC33xx.
Similar to wlcore, all commands eventually reach
__cc33xx_cmd_send which fills a generic command
header and send the buffer via the IO abstraction layer.
Unlike wlcore, there is no polling for command completion
which is received via an interrupt which signals
cc->command_complete.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/cmd.c | 1427 ++++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/cmd.h | 632 ++++++++++++
2 files changed, 2059 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/cmd.c
create mode 100644 drivers/net/wireless/ti/cc33xx/cmd.h
diff --git a/drivers/net/wireless/ti/cc33xx/cmd.c b/drivers/net/wireless/ti/cc33xx/cmd.c
new file mode 100644
index 000000000000..f40f467cf517
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/cmd.c
@@ -0,0 +1,1427 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "acx.h"
+#include "event.h"
+#include "io.h"
+#include "tx.h"
+
+#define CC33XX_REBOOT_TIMEOUT_MSEC 100
+
+static void init_cmd_header(struct cc33xx_cmd_header *header,
+ size_t cmd_len, u16 id)
+{
+ header->nab_header.len = cpu_to_le16(cmd_len);
+ WARN_ON(le16_to_cpu(header->nab_header.len) != cmd_len);
+
+ header->nab_header.sync_pattern = cpu_to_le32(CC33XX_HOST_SYNC_PATTERN);
+ header->nab_header.opcode = cpu_to_le16(id);
+}
+
+int cc33xx_set_max_buffer_size(struct cc33xx *cc, enum buffer_size max_buffer_size)
+{
+ switch (max_buffer_size) {
+ case INI_MAX_BUFFER_SIZE:
+ /* INI FILE PAYLOAD SIZE + INI CMD PARAM + INT */
+ cc->max_cmd_size = CC33XX_INI_CMD_MAX_SIZE;
+ cc->max_cmd_size += sizeof(struct cc33xx_cmd_ini_params_download);
+ cc->max_cmd_size += sizeof(u32);
+ break;
+
+ case CMD_MAX_BUFFER_SIZE:
+ cc->max_cmd_size = CC33XX_CMD_MAX_SIZE;
+ break;
+
+ default:
+ dev_warn(cc->dev, "max_buffer_size invalid, not changing buffer size\n");
+ break;
+ }
+
+ return 0;
+}
+
+static int send_buffer(struct cc33xx *cc, int cmd_box_addr,
+ void *buf, size_t len)
+{
+ size_t max_cmd_size_align;
+
+ memcpy(cc->cmd_buf, buf, len);
+
+ memset(cc->cmd_buf + len, 0, (CC33XX_CMD_BUFFER_SIZE) - len);
+
+ max_cmd_size_align = __ALIGN_MASK(cc->max_cmd_size,
+ CC33XX_BUS_BLOCK_SIZE * 2 - 1);
+
+ return cc33xx_raw_write(cc, cmd_box_addr, cc->cmd_buf,
+ max_cmd_size_align, true);
+}
+
+/* send command to firmware
+ *
+ * @cc: cc struct
+ * @id: command id
+ * @buf: buffer containing the command, must work with dma
+ * @len: length of the buffer
+ * return the cmd status code on success.
+ */
+static int __cc33xx_cmd_send(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, size_t res_len, bool sync)
+{
+ struct cc33xx_cmd_header *cmd;
+ unsigned long timeout;
+ int ret;
+
+ if (id >= CMD_LAST_SUPPORTED_COMMAND) {
+ cc33xx_debug(cc->dev, DEBUG_CMD, "command ID: %d, blocked\n", id);
+ return CMD_STATUS_SUCCESS;
+ }
+
+ if (WARN_ON(len < sizeof(*cmd)) ||
+ WARN_ON(len > cc->max_cmd_size) ||
+ WARN_ON(len % 4 != 0))
+ return -EIO;
+
+ cmd = buf;
+ cmd->id = cpu_to_le16(id);
+ cmd->status = 0;
+
+ init_cmd_header(cmd, len, id);
+
+ guard(mutex)(&cc->cmd_lock);
+
+ init_completion(&cc->command_complete);
+ ret = send_buffer(cc, CC33XX_NAB_DATA_ADDR, buf, len);
+
+ if (ret < 0)
+ return ret;
+
+ if (unlikely(!sync))
+ return CMD_STATUS_SUCCESS;
+
+ timeout = msecs_to_jiffies(CC33XX_COMMAND_TIMEOUT);
+
+ ret = wait_for_completion_timeout(&cc->command_complete, timeout);
+
+ if (ret < 1) {
+ cc33xx_debug(cc->dev, DEBUG_CMD, "Command T.O\n");
+ return -EIO;
+ }
+
+ if (!res_len)
+ return CMD_STATUS_SUCCESS; /* Response should be discarded */
+
+ if (WARN_ON(cc->result_length > res_len)) {
+ dev_err(cc->dev, "Error, insufficient response buffer\n");
+ return -EINVAL;
+ }
+
+ switch (id) {
+ case CMD_INTERROGATE:
+ case CMD_DEBUG_READ:
+ case CMD_TEST_MODE:
+ case CMD_BM_READ_DEVICE_INFO:
+ memcpy(buf + sizeof(struct nab_header), cc->command_result,
+ cc->result_length);
+ break;
+ default:
+ memcpy(buf, cc->command_result, cc->result_length);
+ break;
+ }
+
+ return CMD_STATUS_SUCCESS;
+}
+
+/* send command to fw and return cmd status on success
+ * valid_rets contains a bitmap of allowed error codes
+ */
+static int cc33xx_cmd_send_failsafe(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, size_t res_len,
+ unsigned long valid_rets)
+{
+ int ret = __cc33xx_cmd_send(cc, id, buf, len, res_len, true);
+
+ if (ret < 0)
+ goto fail;
+
+ /* success is always a valid status */
+ valid_rets |= BIT(CMD_STATUS_SUCCESS);
+
+ if (ret >= MAX_COMMAND_STATUS || !test_bit(ret, &valid_rets)) {
+ dev_err(cc->dev, "command execute failure %d\n", ret);
+ ret = -EIO;
+ }
+
+ return ret;
+fail:
+ cc33xx_queue_recovery_work(cc);
+ return ret;
+}
+
+/* wrapper for cc33xx_cmd_send that accept only CMD_STATUS_SUCCESS
+ * return 0 on success.
+ */
+int cc33xx_cmd_send(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, size_t res_len)
+{
+ int ret;
+
+ if ((enum cc33xx_cmd)id >= CMD_LAST_SUPPORTED_COMMAND)
+ return 0;
+
+ /* Support id */
+ switch ((enum cc33xx_cmd)id) {
+ case CMD_EMPTY:
+ case CMD_START_DHCP_MGMT_SEQ:
+ case CMD_STOP_DHCP_MGMT_SEQ:
+ case CMD_START_SECURITY_MGMT_SEQ:
+ case CMD_STOP_SECURITY_MGMT_SEQ:
+ case CMD_START_ARP_MGMT_SEQ:
+ case CMD_STOP_ARP_MGMT_SEQ:
+ case CMD_START_DNS_MGMT_SEQ:
+ case CMD_STOP_DNS_MGMT_SEQ:
+ case CMD_SEND_DEAUTH_DISASSOC:
+ case CMD_SCHED_STATE_EVENT:
+ return 0;
+ default:
+ break;
+ }
+
+ ret = cc33xx_cmd_send_failsafe(cc, id, buf, len, res_len, 0);
+ if (ret < 0)
+ return ret;
+ return 0;
+}
+
+static int cc33xx_count_role_set_bits(unsigned long role_map)
+{
+ int count = 0;
+ /* if device bit is set ( BIT_2 = ROLE_DEVICE)
+ * since role device is not counted
+ * remove it from map
+ */
+ role_map &= ~BIT(2);
+
+ while (role_map != 0) {
+ count += role_map & 1;
+ role_map >>= 1;
+ }
+
+ return count;
+}
+
+int cc33xx_cmd_role_enable(struct cc33xx *cc, const u8 *addr,
+ u8 role_type, u8 *role_id)
+{
+ int ret;
+ unsigned long role_count;
+ union cc33xx_cmd_role_enable_command *buf __free(kfree) = NULL;
+
+ role_count = *cc->roles_map;
+ ret = cc33xx_count_role_set_bits(role_count);
+
+ /* do not enable more than 2 roles at once, exception is device role */
+ if (ret >= 2 && role_type != CC33XX_ROLE_DEVICE) {
+ dev_err(cc->dev, "failed to initiate cmd role enable\n");
+ return -EBUSY;
+ }
+
+ if (WARN_ON(*role_id != CC33XX_INVALID_ROLE_ID))
+ return -EBUSY;
+
+ buf = kzalloc_obj(*buf);
+ if (!buf)
+ return -ENOMEM;
+
+ memcpy(buf->cmd.mac_address, addr, ETH_ALEN);
+ buf->cmd.role_type = role_type;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_ENABLE, &buf->cmd, sizeof(buf->cmd),
+ sizeof(buf->resp));
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role enable\n");
+ return ret;
+ }
+ __set_bit(buf->resp.role_id, cc->roles_map);
+ *role_id = buf->resp.role_id;
+
+ return ret;
+}
+
+int cc33xx_cmd_role_disable(struct cc33xx *cc, u8 *role_id)
+{
+ struct cc33xx_cmd_role_disable *cmd __free(kfree) = NULL;
+ int ret;
+
+ if (WARN_ON(*role_id == CC33XX_INVALID_ROLE_ID))
+ return -ENOENT;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = *role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role disable\n");
+ return ret;
+ }
+
+ __clear_bit(*role_id, cc->roles_map);
+ *role_id = CC33XX_INVALID_ROLE_ID;
+
+ return ret;
+}
+
+int cc33xx_set_link(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 link)
+{
+ guard(mutex)(&cc->mutex);
+
+ /* these bits are used by op_tx */
+ scoped_guard(spinlock_irqsave, &cc->cc_lock) {
+ __set_bit(link, cc->links_map);
+ __set_bit(link, wlvif->links_map);
+ }
+ cc->links[link].wlvif = wlvif;
+
+ /* Take saved value for total freed packets from wlvif, in case this is
+ * recovery/resume
+ */
+ if (wlvif->bss_type != BSS_TYPE_AP_BSS)
+ cc->links[link].total_freed_pkts = wlvif->total_freed_pkts;
+
+ cc->active_link_count++;
+
+ return 0;
+}
+
+void cc33xx_clear_link(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 *hlid)
+{
+ if (*hlid == CC33XX_INVALID_LINK_ID)
+ return;
+
+ guard(mutex)(&cc->mutex);
+
+ /* these bits are used by op_tx */
+ scoped_guard(spinlock_irqsave, &cc->cc_lock) {
+ __clear_bit(*hlid, cc->links_map);
+ __clear_bit(*hlid, wlvif->links_map);
+ }
+
+ cc->links[*hlid].prev_freed_pkts = 0;
+ cc->links[*hlid].ba_bitmap = 0;
+ eth_zero_addr(cc->links[*hlid].addr);
+
+ /* At this point op_tx() will not add more packets to the queues. We
+ * can purge them.
+ */
+ cc33xx_tx_reset_link_queues(cc, *hlid);
+ cc->links[*hlid].wlvif = NULL;
+
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS &&
+ *hlid == wlvif->ap.bcast_hlid) {
+ u32 sqn_padding = CC33XX_TX_SQN_POST_RECOVERY_PADDING;
+ /* save the total freed packets in the wlvif, in case this is
+ * recovery or suspend
+ */
+ wlvif->total_freed_pkts = cc->links[*hlid].total_freed_pkts;
+
+ /* increment the initial seq number on recovery to account for
+ * transmitted packets that we haven't yet got in the FW status
+ */
+ if (test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags))
+ wlvif->total_freed_pkts += sqn_padding;
+ }
+
+ cc->links[*hlid].total_freed_pkts = 0;
+
+ *hlid = CC33XX_INVALID_LINK_ID;
+ cc->active_link_count--;
+ WARN_ON_ONCE(cc->active_link_count < 0);
+}
+
+static u8 cc33xx_get_native_channel_type(u8 nl_channel_type)
+{
+ switch (nl_channel_type) {
+ case NL80211_CHAN_NO_HT:
+ return CC33XX_CHAN_NO_HT;
+ case NL80211_CHAN_HT20:
+ return CC33XX_CHAN_HT20;
+ case NL80211_CHAN_HT40MINUS:
+ return CC33XX_CHAN_HT40MINUS;
+ case NL80211_CHAN_HT40PLUS:
+ return CC33XX_CHAN_HT40PLUS;
+ default:
+ WARN_ON(1);
+ return CC33XX_CHAN_NO_HT;
+ }
+}
+
+static int cc33xx_cmd_role_start_dev(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum nl80211_band band, int channel)
+{
+ int ret;
+ union cc33xx_cmd_role_start_command *buf __free(kfree) = NULL;
+
+ buf = kzalloc_obj(*buf);
+ if (!buf)
+ return -ENOMEM;
+
+ buf->cmd.role_id = wlvif->dev_role_id;
+ buf->cmd.role_type = CC33XX_ROLE_DEVICE;
+ if (band == NL80211_BAND_5GHZ)
+ buf->cmd.band = CC33XX_BAND_5GHZ;
+ buf->cmd.channel = channel;
+ buf->cmd.channel_type = cc33xx_get_native_channel_type(wlvif->channel_type);
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_START, &buf->cmd, sizeof(buf->cmd),
+ sizeof(buf->resp));
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role device start\n");
+ return ret;
+ }
+
+ scoped_guard(mutex, &cc->mutex) {
+ wlvif->dev_hlid = buf->resp.sta.hlid;
+
+ cc->links[wlvif->dev_hlid].allocated_pkts = 0;
+ cc->session_ids[wlvif->dev_hlid] = buf->resp.sta.session;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d\n",
+ wlvif->dev_role_id, buf->resp.sta.hlid,
+ buf->resp.sta.session);
+ cc33xx_set_link(cc, wlvif, wlvif->dev_hlid);
+
+ return 0;
+}
+
+int cc33xx_cmd_role_stop_transceiver(struct cc33xx *cc)
+{
+ struct cc33xx_cmd_role_stop *cmd __free(kfree) = NULL;
+ int ret;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON || !cc->plt))
+ return -EINVAL;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = cc->plt_role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "transceiver - failed to initiate cmd role stop\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_plt_disable(struct cc33xx *cc)
+{
+ struct cc33xx_cmd_PLT_disable *cmd __free(kfree) = NULL;
+ int ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ ret = cc33xx_cmd_send(cc, CMD_PLT_DISABLE, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "transceiver: failed to disable Transceiver mode\n");
+
+ return ret;
+}
+
+static int cc333xx_cmd_role_stop_dev(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif)
+{
+ struct cc33xx_cmd_role_stop *cmd __free(kfree) = NULL;
+ int ret;
+
+ if (WARN_ON(wlvif->dev_hlid == CC33XX_INVALID_LINK_ID))
+ return -EINVAL;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = wlvif->dev_role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role stop\n");
+ return ret;
+ }
+
+ cc33xx_clear_link(cc, wlvif, &wlvif->dev_hlid);
+
+ return ret;
+}
+
+int cc33xx_cmd_plt_enable(struct cc33xx *cc)
+{
+ struct cc33xx_cmd_PLT_enable *cmd __free(kfree) = NULL;
+ s32 ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ ret = cc33xx_cmd_send(cc, CMD_PLT_ENABLE, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "Failed to send CMD_PLT_ENABLE\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_role_start_transceiver(struct cc33xx *cc, u8 role_id)
+{
+ struct cc33xx_cmd_role_start *cmd __free(kfree) = NULL;
+ s32 ret;
+ u8 role_type = ROLE_TRANSCEIVER;
+
+ /* Default values */
+ u8 band = NL80211_BAND_2GHZ;
+ u8 channel = 6;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_type = role_type;
+ cmd->role_id = role_id;
+ cmd->channel = channel;
+ cmd->band = band;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to initiate cmd role start PLT\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_role_start_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+ union cc33xx_cmd_role_start_command *buf __free(kfree) = NULL;
+
+ u32 supported_rates;
+ int ret;
+
+ buf = kzalloc_obj(*buf);
+ if (!buf)
+ return -ENOMEM;
+
+ buf->cmd.role_id = wlvif->role_id;
+ buf->cmd.role_type = CC33XX_ROLE_STA;
+ buf->cmd.channel = wlvif->channel;
+ if (wlvif->band == NL80211_BAND_5GHZ) {
+ buf->cmd.band = CC33XX_BAND_5GHZ;
+ buf->cmd.sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set
+ & ~CONF_TX_CCK_RATES);
+ } else {
+ buf->cmd.sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
+ }
+ buf->cmd.sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
+ buf->cmd.sta.ssid_type = CC33XX_SSID_TYPE_ANY;
+ buf->cmd.sta.ssid_len = wlvif->ssid_len;
+ memcpy(buf->cmd.sta.ssid, wlvif->ssid, wlvif->ssid_len);
+ memcpy(buf->cmd.sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
+
+ supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | wlvif->rate_set;
+ if (wlvif->band == NL80211_BAND_5GHZ)
+ supported_rates &= ~CONF_TX_CCK_RATES;
+
+ if (wlvif->p2p)
+ supported_rates &= ~CONF_TX_CCK_RATES;
+
+ buf->cmd.sta.local_rates = cpu_to_le32(supported_rates);
+
+ buf->cmd.channel_type = cc33xx_get_native_channel_type(wlvif->channel_type);
+
+ /* We don't have the correct remote rates in this stage. The
+ * rates will be reconfigured later, after association, if the
+ * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
+ * we can do, so use all supported_rates here.
+ */
+ buf->cmd.sta.remote_rates = cpu_to_le32(supported_rates);
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_START, &buf->cmd, sizeof(buf->cmd),
+ sizeof(buf->resp));
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role start sta\n");
+ return ret;
+ }
+
+ scoped_guard(mutex, &cc->mutex) {
+ wlvif->sta.role_chan_type = wlvif->channel_type;
+
+ wlvif->sta.hlid = buf->resp.sta.hlid;
+ cc->links[wlvif->sta.hlid].allocated_pkts = 0;
+ cc->session_ids[wlvif->sta.hlid] = buf->resp.sta.session;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d basic_rate_set: 0x%x, remote_rates: 0x%x\n",
+ wlvif->role_id,
+ buf->resp.sta.hlid, buf->resp.sta.session,
+ wlvif->basic_rate_set, wlvif->rate_set);
+ cc33xx_set_link(cc, wlvif, wlvif->sta.hlid);
+
+ return 0;
+}
+
+int cc33xx_cmd_role_stop_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct cc33xx_cmd_role_stop *cmd __free(kfree) = NULL;
+ int ret;
+
+ if (WARN_ON(wlvif->sta.hlid == CC33XX_INVALID_LINK_ID))
+ return -EINVAL;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = wlvif->role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role stop sta\n");
+ return ret;
+ }
+
+ cc33xx_clear_link(cc, wlvif, &wlvif->sta.hlid);
+
+ return ret;
+}
+
+int cc33xx_cmd_role_start_ap(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ union cc33xx_cmd_role_start_command *buf __free(kfree) = NULL;
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+ struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
+ u32 supported_rates;
+ int ret;
+
+ /* If MESH --> ssid_len is always 0 */
+ if (!ieee80211_vif_is_mesh(vif)) {
+ /* trying to use hidden SSID with an old hostapd version */
+ if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
+ dev_err(cc->dev, "got a null SSID from beacon/bss\n");
+ return -EINVAL;
+ }
+ }
+
+ buf = kzalloc_obj(*buf);
+ if (!buf)
+ return -ENOMEM;
+
+ buf->cmd.role_id = wlvif->role_id;
+ buf->cmd.role_type = CC33XX_ROLE_AP;
+ buf->cmd.ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
+ buf->cmd.ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
+ buf->cmd.ap.dtim_interval = bss_conf->dtim_period;
+ buf->cmd.ap.wmm = wlvif->wmm_enabled;
+ buf->cmd.channel = wlvif->channel;
+ buf->cmd.channel_type = cc33xx_get_native_channel_type(wlvif->channel_type);
+
+ supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
+ if (wlvif->p2p)
+ supported_rates &= ~CONF_TX_CCK_RATES;
+
+ buf->cmd.ap.local_rates = cpu_to_le32(supported_rates);
+
+ switch (wlvif->band) {
+ case NL80211_BAND_2GHZ:
+ buf->cmd.band = CC33XX_BAND_2_4GHZ;
+ break;
+ case NL80211_BAND_5GHZ:
+ buf->cmd.band = CC33XX_BAND_5GHZ;
+ break;
+ default:
+ dev_warn(cc->dev, "ap start - unknown band: %d\n", (int)wlvif->band);
+ buf->cmd.band = CC33XX_BAND_2_4GHZ;
+ break;
+ }
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_START, buf, sizeof(buf->cmd),
+ sizeof(buf->resp));
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role start ap\n");
+ return ret;
+ }
+
+ scoped_guard(mutex, &cc->mutex) {
+ wlvif->ap.global_hlid = buf->resp.ap.global_hlid;
+ wlvif->ap.bcast_hlid = buf->resp.ap.broadcast_hlid;
+ cc->session_ids[wlvif->ap.global_hlid] = buf->resp.ap.global_session_id;
+ cc->session_ids[wlvif->ap.bcast_hlid] = buf->resp.ap.bcast_session_id;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_CMD, "role start: roleid=%d, global_hlid=%d, broadcast_hlid=%d, global_session_id=%d, bcast_session_id=%d, basic_rate_set: 0x%x, remote_rates: 0x%x\n",
+ wlvif->role_id,
+ buf->resp.ap.global_hlid,
+ buf->resp.ap.broadcast_hlid,
+ buf->resp.ap.global_session_id,
+ buf->resp.ap.bcast_session_id,
+ wlvif->basic_rate_set, wlvif->rate_set);
+
+ cc33xx_set_link(cc, wlvif, wlvif->ap.global_hlid);
+ cc33xx_set_link(cc, wlvif, wlvif->ap.bcast_hlid);
+
+ return 0;
+}
+
+int cc33xx_cmd_role_stop_ap(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct cc33xx_cmd_role_stop *cmd __free(kfree) = NULL;
+ int ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = wlvif->role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd role stop ap\n");
+ return ret;
+ }
+
+ cc33xx_clear_link(cc, wlvif, &wlvif->ap.bcast_hlid);
+ cc33xx_clear_link(cc, wlvif, &wlvif->ap.global_hlid);
+
+ return ret;
+}
+
+/* send test command to firmware
+ *
+ * @cc: cc struct
+ * @buf: buffer containing the command, with all headers, must work with dma
+ * @len: length of the buffer
+ * @answer: is answer needed
+ */
+int cc33xx_cmd_test(struct cc33xx *cc, void *buf, size_t buf_len, u8 answer)
+{
+ int ret;
+ size_t res_len = 0;
+
+ if (answer)
+ res_len = buf_len;
+
+ ret = cc33xx_cmd_send(cc, CMD_TEST_MODE, buf, buf_len, res_len);
+
+ if (ret < 0)
+ dev_warn(cc->dev, "TEST command failed\n");
+
+ return ret;
+}
+
+/* read acx from firmware
+ *
+ * @cc: cc struct
+ * @id: acx id
+ * @buf: buffer for the response, including all headers, must work with dma
+ * @len: length of buf
+ */
+int cc33xx_cmd_interrogate(struct cc33xx *cc, u16 id, void *buf,
+ size_t cmd_len, size_t res_len)
+{
+ struct acx_header *acx = buf;
+ int ret;
+
+ acx->id = cpu_to_le16(id);
+
+ /* response payload length, does not include any headers */
+ acx->len = cpu_to_le16(res_len - sizeof(*acx));
+
+ ret = cc33xx_cmd_send(cc, CMD_INTERROGATE, acx, cmd_len, res_len);
+ if (ret < 0)
+ dev_err(cc->dev, "INTERROGATE command failed\n");
+
+ return ret;
+}
+
+/* read debug acx from firmware
+ *
+ * @cc: cc struct
+ * @id: acx id
+ * @buf: buffer for the response, including all headers, must work with dma
+ * @len: length of buf
+ */
+int cc33xx_cmd_debug_inter(struct cc33xx *cc, u16 id, void *buf,
+ size_t cmd_len, size_t res_len)
+{
+ struct acx_header *acx = buf;
+ int ret;
+
+ acx->id = cpu_to_le16(id);
+
+ /* response payload length, does not include any headers */
+ acx->len = cpu_to_le16(res_len - sizeof(*acx));
+
+ ret = cc33xx_cmd_send(cc, CMD_DEBUG_READ, acx, cmd_len, res_len);
+ if (ret < 0)
+ dev_err(cc->dev, "CMD_DEBUG_READ command failed\n");
+
+ return ret;
+}
+
+/* write acx value to firmware
+ *
+ * @cc: cc struct
+ * @id: acx id
+ * @buf: buffer containing acx, including all headers, must work with dma
+ * @len: length of buf
+ * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
+ * return the cmd status on success.
+ */
+int cc33xx_cmd_configure_failsafe(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, unsigned long valid_rets)
+{
+ struct acx_header *acx = buf;
+ int ret;
+
+ if (WARN_ON_ONCE(len < sizeof(*acx)))
+ return -EIO;
+
+ acx->id = cpu_to_le16(id);
+
+ /* payload length, does not include any headers */
+ acx->len = cpu_to_le16(len - sizeof(*acx));
+
+ ret = cc33xx_cmd_send_failsafe(cc, CMD_CONFIGURE, acx, len, 0,
+ valid_rets);
+ if (ret < 0)
+ dev_warn(cc->dev, "CONFIGURE command NOK\n");
+
+ return ret;
+}
+
+/* wrapper for cc33xx_cmd_configure that accepts only success status.
+ * return 0 on success
+ */
+int cc33xx_cmd_configure(struct cc33xx *cc, u16 id, void *buf, size_t len)
+{
+ int ret = cc33xx_cmd_configure_failsafe(cc, id, buf, len, 0);
+
+ if (ret < 0)
+ return ret;
+ return 0;
+}
+
+/* write acx value to firmware
+ *
+ * @cc: cc struct
+ * @id: acx id
+ * @buf: buffer containing debug, including all headers, must work with dma
+ * @len: length of buf
+ * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
+ * return the cmd status on success.
+ */
+static int cc33xx_cmd_debug_failsafe(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, unsigned long valid_rets)
+{
+ struct debug_header *acx = buf;
+ int ret;
+
+ if (WARN_ON_ONCE(len < sizeof(*acx)))
+ return -EIO;
+
+ acx->id = cpu_to_le16(id);
+
+ /* payload length, does not include any headers */
+ acx->len = cpu_to_le16(len - sizeof(*acx));
+
+ ret = cc33xx_cmd_send_failsafe(cc, CMD_DEBUG, acx, len, 0,
+ valid_rets);
+ if (ret < 0)
+ dev_warn(cc->dev, "CONFIGURE command NOK\n");
+
+ return ret;
+}
+
+/* wrapper for cc33xx_cmd_debug that accepts only success status.
+ * return 0 on success
+ */
+int cc33xx_cmd_debug(struct cc33xx *cc, u16 id, void *buf, size_t len)
+{
+ int ret = cc33xx_cmd_debug_failsafe(cc, id, buf, len, 0);
+
+ if (ret < 0)
+ return ret;
+ return 0;
+}
+
+int cc33xx_cmd_ps_mode(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 ps_mode, u16 auto_ps_timeout)
+{
+ struct cc33xx_cmd_ps_params *ps_params __free(kfree) = NULL;
+ int ret = 0;
+
+ ps_params = kzalloc_obj(*ps_params);
+ if (!ps_params)
+ return -ENOMEM;
+
+ ps_params->role_id = wlvif->role_id;
+ ps_params->ps_mode = ps_mode;
+ ps_params->auto_ps_timeout = cpu_to_le16(auto_ps_timeout);
+
+ ret = cc33xx_cmd_send(cc, CMD_SET_PS_MODE, ps_params,
+ sizeof(*ps_params), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "cmd set_ps_mode failed\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_set_default_wep_key(struct cc33xx *cc, u8 id, u8 hlid)
+{
+ struct cc33xx_cmd_set_keys *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->hlid = hlid;
+ cmd->key_id = id;
+ cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
+ cmd->key_action = cpu_to_le16(KEY_SET_ID);
+ cmd->key_type = KEY_WEP;
+
+ ret = cc33xx_cmd_send(cc, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_warn(cc->dev, "cmd set_default_wep_key failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_cmd_set_sta_key(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 action, u8 id, u8 key_type, u8 key_size,
+ const u8 *key, const u8 *addr, u32 tx_seq_32,
+ u16 tx_seq_16)
+{
+ struct cc33xx_cmd_set_keys *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ /* hlid might have already been deleted */
+ if (wlvif->sta.hlid == CC33XX_INVALID_LINK_ID)
+ return 0;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->hlid = wlvif->sta.hlid;
+
+ if (key_type == KEY_WEP)
+ cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
+ else if (is_broadcast_ether_addr(addr))
+ cmd->lid_key_type = BROADCAST_LID_TYPE;
+ else
+ cmd->lid_key_type = UNICAST_LID_TYPE;
+
+ cmd->key_action = cpu_to_le16(action);
+ cmd->key_size = key_size;
+ cmd->key_type = key_type;
+
+ cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
+ cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
+
+ cmd->key_id = id;
+
+ if (key_type == KEY_TKIP) {
+ /* We get the key in the following form:
+ * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
+ * but the target is expecting:
+ * TKIP - RX MIC - TX MIC
+ */
+ memcpy(cmd->key, key, 16);
+ memcpy(cmd->key + 16, key + 24, 8);
+ memcpy(cmd->key + 24, key + 16, 8);
+
+ } else {
+ memcpy(cmd->key, key, key_size);
+ }
+
+ ret = cc33xx_cmd_send(cc, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_warn(cc->dev, "could not set keys\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_set_ap_key(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 action, u8 id, u8 key_type, u8 key_size,
+ const u8 *key, u8 hlid, u32 tx_seq_32, u16 tx_seq_16)
+{
+ struct cc33xx_cmd_set_keys *cmd __free(kfree) = NULL;
+ int ret = 0;
+ u8 lid_type;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ if (hlid == wlvif->ap.bcast_hlid) {
+ if (key_type == KEY_WEP)
+ lid_type = WEP_DEFAULT_LID_TYPE;
+ else
+ lid_type = BROADCAST_LID_TYPE;
+ } else {
+ lid_type = UNICAST_LID_TYPE;
+ }
+
+ cmd->lid_key_type = lid_type;
+ cmd->hlid = hlid;
+ cmd->key_action = cpu_to_le16(action);
+ cmd->key_size = key_size;
+ cmd->key_type = key_type;
+ cmd->key_id = id;
+ cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
+ cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
+
+ if (key_type == KEY_TKIP) {
+ /* We get the key in the following form:
+ * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
+ * but the target is expecting:
+ * TKIP - RX MIC - TX MIC
+ */
+ memcpy(cmd->key, key, 16);
+ memcpy(cmd->key + 16, key + 24, 8);
+ memcpy(cmd->key + 24, key + 16, 8);
+ } else {
+ memcpy(cmd->key, key, key_size);
+ }
+
+ cc33xx_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
+
+ ret = cc33xx_cmd_send(cc, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_warn(cc->dev, "could not set ap keys\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_set_peer_state(struct cc33xx *cc, u8 hlid)
+{
+ struct cc33xx_cmd_set_peer_state *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->hlid = hlid;
+ cmd->state = CMD_STA_STATE_CONNECTED;
+
+ ret = cc33xx_cmd_send(cc, CMD_SET_LINK_CONNECTION_STATE,
+ cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to send set peer state command\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_add_peer(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta, u8 *hlid, u8 is_connected)
+{
+ union cc33xx_cmd_add_peer_command *buf __free(kfree) = NULL;
+ int i, ret;
+ u32 sta_rates;
+
+ buf = kzalloc_obj(*buf);
+ if (!buf)
+ return -ENOMEM;
+
+ buf->cmd.is_connected = is_connected;
+ buf->cmd.role_id = wlvif->role_id;
+ buf->cmd.role_type = CC33XX_ROLE_AP;
+ buf->cmd.link_type = 1;
+
+ memcpy(buf->cmd.addr, sta->addr, ETH_ALEN);
+ buf->cmd.bss_index = CC33XX_AP_BSS_INDEX;
+ buf->cmd.aid = cpu_to_le16(sta->aid);
+ buf->cmd.sp_len = sta->max_sp;
+ buf->cmd.wmm = sta->wme ? 1 : 0;
+
+ for (i = 0; i < IEEE80211_NUM_ACS; i++) {
+ if (sta->wme && (sta->uapsd_queues & BIT(i))) {
+ buf->cmd.psd_type[IEEE80211_NUM_ACS - 1 - i] =
+ CC33XX_PSD_UPSD_TRIGGER;
+ } else {
+ buf->cmd.psd_type[IEEE80211_NUM_ACS - 1 - i] =
+ CC33XX_PSD_LEGACY;
+ }
+ }
+
+ sta_rates = sta->deflink.supp_rates[wlvif->band];
+ if (sta->deflink.ht_cap.ht_supported) {
+ sta_rates |=
+ (sta->deflink.ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
+ (sta->deflink.ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
+ }
+
+ buf->cmd.supported_rates =
+ cpu_to_le32(cc33xx_tx_enabled_rates_get(cc, sta_rates,
+ wlvif->band));
+
+ if (!buf->cmd.supported_rates)
+ buf->cmd.supported_rates = cpu_to_le32(wlvif->basic_rate_set);
+
+ if (sta->deflink.ht_cap.ht_supported) {
+ buf->cmd.ht_capabilities = cpu_to_le32(sta->deflink.ht_cap.cap);
+ buf->cmd.ht_capabilities |= cpu_to_le32(CC33XX_HT_CAP_HT_OPERATION);
+ buf->cmd.ampdu_params = sta->deflink.ht_cap.ampdu_factor |
+ sta->deflink.ht_cap.ampdu_density;
+ }
+
+ buf->cmd.has_he = sta->deflink.he_cap.has_he;
+ buf->cmd.mfp = sta->mfp;
+ ret = cc33xx_cmd_send(cc, CMD_ADD_PEER, buf, sizeof(buf->cmd),
+ sizeof(buf->resp));
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd add peer\n");
+ return ret;
+ }
+
+ if (hlid) {
+ if (le16_to_cpu(buf->resp.header.status) == CMD_STATUS_SUCCESS) {
+ *hlid = buf->resp.hlid;
+
+ scoped_guard(mutex, &cc->mutex) {
+ cc->links[*hlid].allocated_pkts = 0;
+ cc->session_ids[*hlid] = buf->resp.session_id;
+ }
+ } else {
+ ret = -EMLINK;
+ }
+ }
+
+ return ret;
+}
+
+int cc33xx_cmd_remove_peer(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 hlid)
+{
+ struct cc33xx_cmd_remove_peer *cmd __free(kfree) = NULL;
+ int ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->hlid = hlid;
+
+ cmd->role_id = wlvif->role_id;
+
+ init_completion(&cc->peer_remove_complete);
+
+ ret = cc33xx_cmd_send(cc, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "failed to initiate cmd remove peer\n");
+ return ret;
+ }
+
+ ret = wait_for_completion_timeout(&cc->peer_remove_complete,
+ msecs_to_jiffies(CC33XX_EVENT_TIMEOUT));
+
+ /* If there is a timeout due to event not received, queue recovery */
+ if (!ret) {
+ ret = -ETIMEDOUT;
+ cc33xx_queue_recovery_work(cc);
+ }
+
+ return ret;
+}
+
+static int cc33xx_cmd_roc(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 role_id, enum nl80211_band band, u8 channel)
+{
+ struct cc33xx_cmd_roc *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ if (WARN_ON(role_id == CC33XX_INVALID_ROLE_ID))
+ return -EINVAL;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = role_id;
+ cmd->channel = channel;
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ cmd->band = CC33XX_BAND_2_4GHZ;
+ break;
+ case NL80211_BAND_5GHZ:
+ cmd->band = CC33XX_BAND_5GHZ;
+ break;
+ default:
+ dev_err(cc->dev, "roc - unknown band: %d\n", (int)wlvif->band);
+ return -EINVAL;
+ }
+
+ ret = cc33xx_cmd_send(cc, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to send ROC command\n");
+
+ return ret;
+}
+
+static int cc33xx_cmd_croc(struct cc33xx *cc, u8 role_id)
+{
+ struct cc33xx_cmd_croc *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
+ sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to send ROC command\n");
+
+ return ret;
+}
+
+int cc33xx_roc(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 role_id,
+ enum nl80211_band band, u8 channel)
+{
+ int ret = 0;
+
+ if (WARN_ON(test_bit(role_id, cc->roc_map)))
+ return 0;
+
+ ret = cc33xx_cmd_roc(cc, wlvif, role_id, band, channel);
+ if (!ret)
+ __set_bit(role_id, cc->roc_map);
+
+ return ret;
+}
+
+int cc33xx_croc(struct cc33xx *cc, u8 role_id)
+{
+ int ret = 0;
+
+ if (WARN_ON(!test_bit(role_id, cc->roc_map)))
+ return 0;
+
+ ret = cc33xx_cmd_croc(cc, role_id);
+ if (!ret)
+ __clear_bit(role_id, cc->roc_map);
+
+ return ret;
+}
+
+int cc33xx_cmd_stop_channel_switch(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct cc33xx_cmd_stop_channel_switch *cmd __free(kfree) = NULL;
+ int ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = wlvif->role_id;
+
+ ret = cc33xx_cmd_send(cc, CMD_STOP_CHANNEL_SWITCH,
+ cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to stop channel switch command\n");
+
+ return ret;
+}
+
+/* start dev role and roc on its channel */
+int cc33xx_start_dev(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum nl80211_band band, int channel)
+{
+ int ret;
+
+ if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
+ return -EINVAL;
+
+ /* the dev role is already started for p2p mgmt interfaces */
+
+ if (!cc33xx_is_p2p_mgmt(wlvif)) {
+ ret = cc33xx_cmd_role_enable(cc,
+ cc33xx_wlvif_to_vif(wlvif)->addr,
+ CC33XX_ROLE_DEVICE,
+ &wlvif->dev_role_id);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = cc33xx_cmd_role_start_dev(cc, wlvif, band, channel);
+ if (ret < 0)
+ goto out_disable;
+
+ ret = cc33xx_roc(cc, wlvif, wlvif->dev_role_id, band, channel);
+ if (ret < 0)
+ goto out_stop;
+
+ return 0;
+
+out_stop:
+ cc333xx_cmd_role_stop_dev(cc, wlvif);
+out_disable:
+ if (!cc33xx_is_p2p_mgmt(wlvif))
+ cc33xx_cmd_role_disable(cc, &wlvif->dev_role_id);
+
+ return ret;
+}
+
+/* croc dev hlid, and stop the role. */
+int cc33xx_stop_dev(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret;
+
+ if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
+ return -EINVAL;
+
+ /* flush all pending packets */
+ ret = cc33xx_do_tx_work(cc);
+ if (ret < 0)
+ return ret;
+
+ if (test_bit(wlvif->dev_role_id, cc->roc_map)) {
+ ret = cc33xx_croc(cc, wlvif->dev_role_id);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = cc333xx_cmd_role_stop_dev(cc, wlvif);
+ if (ret < 0)
+ return ret;
+
+ if (!cc33xx_is_p2p_mgmt(wlvif)) {
+ ret = cc33xx_cmd_role_disable(cc, &wlvif->dev_role_id);
+ if (ret < 0)
+ return ret;
+ }
+
+ return ret;
+}
+
+int cc33xx_cmd_channel_switch(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_channel_switch *ch_switch)
+{
+ struct cc33xx_cmd_channel_switch *cmd __free(kfree) = NULL;
+ u32 supported_rates;
+ int ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = wlvif->role_id;
+ cmd->channel = ch_switch->chandef.chan->hw_value;
+ cmd->switch_time = ch_switch->count;
+ cmd->stop_tx = ch_switch->block_tx;
+
+ switch (ch_switch->chandef.chan->band) {
+ case NL80211_BAND_2GHZ:
+ cmd->band = CC33XX_BAND_2_4GHZ;
+ break;
+ case NL80211_BAND_5GHZ:
+ cmd->band = CC33XX_BAND_5GHZ;
+ break;
+ default:
+ dev_err(cc->dev, "invalid channel switch band: %d\n",
+ ch_switch->chandef.chan->band);
+ return -EINVAL;
+ }
+
+ supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
+ supported_rates |= wlvif->rate_set;
+ if (wlvif->p2p)
+ supported_rates &= ~CONF_TX_CCK_RATES;
+ cmd->local_supported_rates = cpu_to_le32(supported_rates);
+ cmd->channel_type = wlvif->channel_type;
+
+ ret = cc33xx_cmd_send(cc, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to send channel switch command\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_set_bd_addr(struct cc33xx *cc, u8 *bd_addr)
+{
+ struct cc33xx_cmd_set_bd_addr *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ memcpy(cmd->bd_addr, bd_addr, sizeof(cmd->bd_addr));
+
+ ret = cc33xx_cmd_send(cc, CMD_SET_BD_ADDR, cmd, sizeof(*cmd), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to set BD address\n");
+
+ return ret;
+}
+
+int cc33xx_cmd_get_device_info(struct cc33xx *cc, u8 *info_buffer, size_t buffer_len)
+{
+ struct cc33xx_cmd_get_device_info *cmd __free(kfree) = NULL;
+ int ret = 0;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ ret = cc33xx_cmd_send(cc, CMD_BM_READ_DEVICE_INFO, cmd,
+ sizeof(*cmd), sizeof(*cmd));
+ if (ret < 0) {
+ dev_err(cc->dev, "Device info command failure\n");
+ } else {
+ WARN_ON(buffer_len > sizeof(cmd->device_info));
+ memcpy(info_buffer, cmd->device_info, buffer_len);
+ }
+
+ return ret;
+}
+
+int cc33xx_cmd_download_container_chunk(struct cc33xx *cc, u8 *chunk,
+ size_t chunk_len, bool is_last_chunk)
+{
+ struct cc33xx_cmd_container_download *cmd __free(kfree) = NULL;
+ const size_t command_size = sizeof(*cmd) + chunk_len;
+ int ret;
+ bool is_sync_transfer = !is_last_chunk;
+
+ cmd = kzalloc(command_size, GFP_KERNEL);
+
+ if (!cmd)
+ return -ENOMEM;
+
+ memcpy(cmd->payload, chunk, chunk_len);
+ cmd->length = cpu_to_le32(chunk_len);
+
+ if (is_last_chunk) {
+ cc33xx_debug(cc->dev, DEBUG_BOOT, "Suspending IRQ while device reboots\n");
+ cc33xx_disable_interrupts_nosync(cc);
+ }
+
+ ret = __cc33xx_cmd_send(cc, CMD_CONTAINER_DOWNLOAD, cmd,
+ command_size, sizeof(u32), is_sync_transfer);
+
+ if (is_last_chunk) {
+ msleep(CC33XX_REBOOT_TIMEOUT_MSEC);
+ cc33xx_enable_interrupts(cc);
+ }
+
+ return ret;
+}
diff --git a/drivers/net/wireless/ti/cc33xx/cmd.h b/drivers/net/wireless/ti/cc33xx/cmd.h
new file mode 100644
index 000000000000..e58d599b84e3
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/cmd.h
@@ -0,0 +1,632 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __CMD_H__
+#define __CMD_H__
+
+#include "cc33xx.h"
+
+enum buffer_size {
+ INI_MAX_BUFFER_SIZE,
+ CMD_MAX_BUFFER_SIZE
+};
+
+int cc33xx_set_max_buffer_size(struct cc33xx *cc, enum buffer_size max_buffer_size);
+int cc33xx_cmd_send(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, size_t res_len);
+int cc33xx_cmd_role_enable(struct cc33xx *cc, const u8 *addr,
+ u8 role_type, u8 *role_id);
+int cc33xx_cmd_role_disable(struct cc33xx *cc, u8 *role_id);
+int cc33xx_cmd_role_start_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_cmd_role_stop_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_cmd_role_start_ap(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_cmd_role_stop_ap(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_start_dev(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum nl80211_band band, int channel);
+int cc33xx_stop_dev(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_cmd_test(struct cc33xx *cc, void *buf, size_t buf_len, u8 answer);
+int cc33xx_cmd_interrogate(struct cc33xx *cc, u16 id, void *buf,
+ size_t cmd_len, size_t res_len);
+int cc33xx_cmd_debug_inter(struct cc33xx *cc, u16 id, void *buf,
+ size_t cmd_len, size_t res_len);
+int cc33xx_cmd_configure(struct cc33xx *cc, u16 id, void *buf, size_t len);
+int cc33xx_cmd_debug(struct cc33xx *cc, u16 id, void *buf, size_t len);
+int cc33xx_cmd_configure_failsafe(struct cc33xx *cc, u16 id, void *buf,
+ size_t len, unsigned long valid_rets);
+int cc33xx_cmd_ps_mode(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 ps_mode, u16 auto_ps_timeout);
+int cc33xx_cmd_set_default_wep_key(struct cc33xx *cc, u8 id, u8 hlid);
+int cc33xx_cmd_set_sta_key(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 action, u8 id, u8 key_type,
+ u8 key_size, const u8 *key, const u8 *addr,
+ u32 tx_seq_32, u16 tx_seq_16);
+int cc33xx_cmd_set_ap_key(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 action, u8 id, u8 key_type, u8 key_size,
+ const u8 *key, u8 hlid, u32 tx_seq_32, u16 tx_seq_16);
+int cc33xx_cmd_set_peer_state(struct cc33xx *cc, u8 hlid);
+int cc33xx_roc(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 role_id,
+ enum nl80211_band band, u8 channel);
+int cc33xx_croc(struct cc33xx *cc, u8 role_id);
+int cc33xx_cmd_add_peer(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta, u8 *hlid, u8 is_connected);
+int cc33xx_cmd_remove_peer(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 hlid);
+int cc33xx_cmd_stop_channel_switch(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_set_link(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 link);
+void cc33xx_clear_link(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 *hlid);
+int cc33xx_cmd_role_start_transceiver(struct cc33xx *cc, u8 role_id);
+int cc33xx_cmd_role_stop_transceiver(struct cc33xx *cc);
+int cc33xx_cmd_plt_enable(struct cc33xx *cc);
+int cc33xx_cmd_plt_disable(struct cc33xx *cc);
+int cc33xx_cmd_channel_switch(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_channel_switch *ch_switch);
+int cc33xx_cmd_set_bd_addr(struct cc33xx *cc, u8 *bd_addr);
+int cc33xx_cmd_get_device_info(struct cc33xx *cc, u8 *info_buffer, size_t buffer_len);
+int cc33xx_cmd_download_container_chunk(struct cc33xx *cc, u8 *chunk,
+ size_t chunk_len, bool is_last_chunk);
+
+enum cc33xx_cmd {
+ CMD_EMPTY,
+ CMD_SET_KEYS = 1,
+ CMD_SET_LINK_CONNECTION_STATE = 2,
+
+ CMD_CHANNEL_SWITCH = 3,
+ CMD_STOP_CHANNEL_SWITCH = 4,
+
+ CMD_REMAIN_ON_CHANNEL = 5,
+ CMD_CANCEL_REMAIN_ON_CHANNEL = 6,
+
+ CMD_START_DHCP_MGMT_SEQ = 7,
+ CMD_STOP_DHCP_MGMT_SEQ = 8,
+
+ CMD_START_SECURITY_MGMT_SEQ = 9,
+ CMD_STOP_SECURITY_MGMT_SEQ = 10,
+
+ CMD_START_ARP_MGMT_SEQ = 11,
+ CMD_STOP_ARP_MGMT_SEQ = 12,
+
+ CMD_START_DNS_MGMT_SEQ = 13,
+ CMD_STOP_DNS_MGMT_SEQ = 14,
+
+ /* Access point commands */
+ CMD_ADD_PEER = 15,
+ CMD_REMOVE_PEER = 16,
+
+ /* Role API */
+ CMD_ROLE_ENABLE = 17,
+ CMD_ROLE_DISABLE = 18,
+ CMD_ROLE_START = 19,
+ CMD_ROLE_STOP = 20,
+
+ CMD_AP_SET_BEACON_INFO = 21, /* Set AP beacon template */
+
+ /* Managed sequence of sending deauth / disassoc frame */
+ CMD_SEND_DEAUTH_DISASSOC = 22,
+
+ CMD_SCHED_STATE_EVENT = 23,
+ CMD_SCAN = 24,
+ CMD_STOP_SCAN = 25,
+ CMD_SET_PROBE_IE = 26,
+
+ CMD_CONFIGURE = 27,
+ CMD_INTERROGATE = 28,
+
+ CMD_DEBUG = 29,
+ CMD_DEBUG_READ = 30,
+
+ CMD_TEST_MODE = 31,
+ CMD_PLT_ENABLE = 32,
+ CMD_PLT_DISABLE = 33,
+ CMD_CONNECTION_SCAN_SSID_CFG = 34,
+ CMD_BM_READ_DEVICE_INFO = 35,
+ CMD_CONTAINER_DOWNLOAD = 36,
+ CMD_DOWNLOAD_INI_PARAMS = 37,
+ CMD_SET_BD_ADDR = 38,
+ CMD_BLE_COMMANDS = 39,
+
+ CMD_LAST_SUPPORTED_COMMAND,
+
+ /* The following commands are legacy and are not yet supported */
+
+ CMD_SET_PS_MODE,
+
+ MAX_COMMAND_ID_CC33XX = 0x7FFF,
+};
+
+#define MAX_CMD_PARAMS 572
+
+/* unit ms */
+#define CC33XX_COMMAND_TIMEOUT 2000
+#define CC33XX_CMD_TEMPL_MAX_SIZE 512
+#define CC33XX_EVENT_TIMEOUT 5000
+
+struct cc33xx_cmd_header {
+ struct nab_header nab_header;
+ __le16 id;
+ __le16 status;
+
+ /* payload */
+ u8 data[];
+} __packed;
+
+#define CC33XX_CMD_MAX_PARAMS 572
+
+struct cc33xx_command {
+ struct cc33xx_cmd_header header;
+ u8 parameters[CC33XX_CMD_MAX_PARAMS];
+} __packed;
+
+enum {
+ CMD_MAILBOX_IDLE = 0,
+ CMD_STATUS_SUCCESS = 1,
+ CMD_STATUS_UNKNOWN_CMD = 2,
+ CMD_STATUS_UNKNOWN_IE = 3,
+ CMD_STATUS_REJECT_MEAS_SG_ACTIVE = 11,
+ CMD_STATUS_RX_BUSY = 13,
+ CMD_STATUS_INVALID_PARAM = 14,
+ CMD_STATUS_TEMPLATE_TOO_LARGE = 15,
+ CMD_STATUS_OUT_OF_MEMORY = 16,
+ CMD_STATUS_STA_TABLE_FULL = 17,
+ CMD_STATUS_RADIO_ERROR = 18,
+ CMD_STATUS_WRONG_NESTING = 19,
+ CMD_STATUS_TIMEOUT = 21, /* Driver internal use.*/
+ CMD_STATUS_FW_RESET = 22, /* Driver internal use.*/
+ CMD_STATUS_TEMPLATE_OOM = 23,
+ CMD_STATUS_NO_RX_BA_SESSION = 24,
+
+ MAX_COMMAND_STATUS
+};
+
+enum {
+ BSS_TYPE_IBSS = 0,
+ BSS_TYPE_STA_BSS = 2,
+ BSS_TYPE_AP_BSS = 3,
+ MAX_BSS_TYPE = 0xFF
+};
+
+struct cc33xx_cmd_role_enable {
+ struct cc33xx_cmd_header header;
+
+ u8 role_type;
+ u8 mac_address[ETH_ALEN];
+ u8 padding;
+} __packed;
+
+struct command_complete_header {
+ __le16 id;
+ __le16 status;
+
+ /* payload */
+ u8 data[];
+} __packed;
+
+struct cc33xx_cmd_complete_role_enable {
+ struct command_complete_header header;
+ u8 role_id;
+ u8 padding[3];
+} __packed;
+
+union cc33xx_cmd_role_enable_command {
+ struct cc33xx_cmd_role_enable cmd;
+ struct cc33xx_cmd_complete_role_enable resp;
+} __packed;
+
+struct cc33xx_cmd_role_disable {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 padding[3];
+} __packed;
+
+enum cc33xx_band {
+ CC33XX_BAND_2_4GHZ = 0,
+ CC33XX_BAND_5GHZ = 1,
+ CC33XX_BAND_JAPAN_4_9_GHZ = 2,
+ CC33XX_BAND_DEFAULT = CC33XX_BAND_2_4GHZ,
+ CC33XX_BAND_INVALID = 0x7E,
+ CC33XX_BAND_MAX_RADIO = 0x7F,
+};
+
+enum cc33xx_channel_type {
+ CC33XX_CHAN_NO_HT,
+ CC33XX_CHAN_HT20,
+ CC33XX_CHAN_HT40MINUS,
+ CC33XX_CHAN_HT40PLUS
+};
+
+struct cc33xx_cmd_role_start {
+ struct cc33xx_cmd_header header;
+ u8 role_id;
+ u8 role_type;
+ u8 band;
+ u8 channel;
+
+ u8 channel_type;
+
+ union {
+ struct {
+ u8 padding_1[54];
+ } __packed device;
+ /* sta & p2p_cli use the same struct */
+ struct {
+ u8 bssid[ETH_ALEN];
+
+ __le32 remote_rates; /* remote supported rates */
+
+ /* The target uses this field to determine the rate at
+ * which to transmit control frame responses (such as
+ * ACK or CTS frames).
+ */
+ __le32 basic_rate_set;
+ __le32 local_rates; /* local supported rates */
+
+ u8 ssid_type;
+ u8 ssid_len;
+ u8 ssid[IEEE80211_MAX_SSID_LEN];
+
+ __le16 beacon_interval; /* in TBTTs */
+ } __packed sta;
+ struct {
+ u8 bssid[ETH_ALEN];
+ u8 hlid; /* data hlid */
+ u8 dtim_interval;
+ __le32 remote_rates; /* remote supported rates */
+
+ __le32 basic_rate_set;
+ __le32 local_rates; /* local supported rates */
+
+ u8 ssid_type;
+ u8 ssid_len;
+ u8 ssid[IEEE80211_MAX_SSID_LEN];
+
+ __le16 beacon_interval; /* in TBTTs */
+
+ u8 padding_1[2];
+ } __packed ibss;
+ /* ap & p2p_go use the same struct */
+ struct {
+ __le16 beacon_interval; /* in TBTTs */
+
+ __le32 basic_rate_set;
+ __le32 local_rates; /* local supported rates */
+
+ u8 dtim_interval;
+ /* ap supports wmm (note that there is additional
+ * per-sta wmm configuration)
+ */
+ u8 wmm;
+ u8 padding_1[42];
+ } __packed ap;
+ };
+ u8 padding;
+} __packed;
+
+struct cc33xx_cmd_complete_role_start {
+ struct command_complete_header header;
+ union {
+ struct {
+ u8 hlid;
+ u8 session;
+ u8 padding[2];
+ } __packed sta;
+ struct {
+ /* The host link id for the AP's global queue */
+ u8 global_hlid;
+ /* The host link id for the AP's broadcast queue */
+ u8 broadcast_hlid;
+ u8 bcast_session_id;
+ u8 global_session_id;
+ } __packed ap;
+ };
+} __packed;
+
+union cc33xx_cmd_role_start_command {
+ struct cc33xx_cmd_role_start cmd;
+ struct cc33xx_cmd_complete_role_start resp;
+} __packed;
+
+struct cc33xx_cmd_role_stop {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 padding[3];
+} __packed;
+
+struct cmd_enabledisable_path {
+ struct cc33xx_cmd_header header;
+
+ u8 channel;
+ u8 padding[3];
+} __packed;
+
+enum cc33xx_cmd_ps_mode_e {
+ STATION_AUTO_PS_MODE, /* Dynamic Power Save */
+ STATION_ACTIVE_MODE,
+ STATION_POWER_SAVE_MODE
+};
+
+struct cc33xx_cmd_ps_params {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 ps_mode; /* STATION_* */
+ __le16 auto_ps_timeout;
+} __packed;
+
+/* HW encryption keys */
+enum cc33xx_cmd_key_action {
+ KEY_ADD_OR_REPLACE = 1,
+ KEY_REMOVE = 2,
+ KEY_SET_ID = 3,
+ MAX_KEY_ACTION = 0xffff,
+};
+
+enum cc33xx_cmd_lid_key_type {
+ UNICAST_LID_TYPE = 0,
+ BROADCAST_LID_TYPE = 1,
+ WEP_DEFAULT_LID_TYPE = 2
+};
+
+enum cc33xx_cmd_key_type {
+ KEY_NONE = 0,
+ KEY_WEP = 1,
+ KEY_TKIP = 2,
+ KEY_AES = 3, /* aes_ccmp_128 */
+ KEY_GEM = 4, /* Not supported */
+ KEY_IGTK = 5, /* bip_cmac_128 */
+ KEY_CMAC_256 = 6,
+ KEY_GMAC_128 = 7,
+ KEY_GMAC_256 = 8,
+ KEY_GCMP_256 = 9,
+ KEY_CCMP256 = 10,
+ KEY_GCMP128 = 11,
+};
+
+struct cc33xx_cmd_set_keys {
+ struct cc33xx_cmd_header header;
+
+ /* Indicates whether the HLID is a unicast key set
+ * or broadcast key set. A special value 0xFF is
+ * used to indicate that the HLID is on WEP-default
+ * (multi-hlids). of type cc33xx_cmd_lid_key_type.
+ */
+ u8 hlid;
+
+ /* In WEP-default network (hlid == 0xFF) used to
+ * indicate which network STA/IBSS/AP role should be
+ * changed
+ */
+ u8 lid_key_type;
+
+ /* Key ID - For TKIP and AES key types, this field
+ * indicates the value that should be inserted into
+ * the KeyID field of frames transmitted using this
+ * key entry. For broadcast keys the index use as a
+ * marker for TX/RX key.
+ * For WEP default network (HLID=0xFF), this field
+ * indicates the ID of the key to add or remove.
+ */
+ u8 key_id;
+ u8 reserved_1;
+
+ /* key_action_e */
+ __le16 key_action;
+
+ /* key size in bytes */
+ u8 key_size;
+
+ /* key_type_e */
+ u8 key_type;
+
+ /* This field holds the security key data to add to the STA table */
+ u8 key[MAX_KEY_SIZE];
+ __le16 ac_seq_num16[IEEE80211_NUM_ACS];
+ __le32 ac_seq_num32[IEEE80211_NUM_ACS];
+} __packed;
+
+struct cc33xx_cmd_test_header {
+ u8 id;
+ u8 padding[3];
+} __packed;
+
+#define CMD_STA_STATE_CONNECTED 1
+
+struct cc33xx_cmd_set_peer_state {
+ struct cc33xx_cmd_header header;
+
+ u8 hlid;
+ u8 state;
+ u8 padding[2];
+} __packed;
+
+struct cc33xx_cmd_roc {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 channel;
+ u8 band;
+ u8 padding;
+};
+
+struct cc33xx_cmd_croc {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 padding[3];
+};
+
+enum cc33xx_ssid_type {
+ CC33XX_SSID_TYPE_PUBLIC = 0,
+ CC33XX_SSID_TYPE_HIDDEN = 1,
+ CC33XX_SSID_TYPE_ANY = 2,
+};
+
+enum CC33XX_psd_type {
+ CC33XX_PSD_LEGACY = 0,
+ CC33XX_PSD_UPSD_TRIGGER = 1,
+ CC33XX_PSD_LEGACY_PSPOLL = 2,
+ CC33XX_PSD_SAPSD = 3
+};
+
+#define MAX_SIZE_BEACON_TEMP (450)
+struct cc33xx_cmd_set_beacon_info {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ __le16 beacon_len;
+ u8 beacon[MAX_SIZE_BEACON_TEMP];
+ u8 padding[3];
+} __packed;
+
+struct cc33xx_cmd_add_peer {
+ struct cc33xx_cmd_header header;
+
+ u8 is_connected;
+ u8 role_id;
+ u8 role_type;
+ u8 link_type;
+ u8 addr[ETH_ALEN];
+ __le16 aid;
+ u8 psd_type[IEEE80211_NUM_ACS];
+ __le32 supported_rates;
+ u8 bss_index;
+ u8 sp_len;
+ u8 wmm;
+ __le32 ht_capabilities;
+ u8 ampdu_params;
+
+ /* HE peer support */
+ bool has_he;
+ bool mfp;
+ u8 padding[2];
+} __packed;
+
+struct cc33xx_cmd_complete_add_peer {
+ struct command_complete_header header;
+ u8 hlid;
+ u8 session_id;
+} __packed;
+
+union cc33xx_cmd_add_peer_command {
+ struct cc33xx_cmd_add_peer cmd;
+ struct cc33xx_cmd_complete_add_peer resp;
+} __packed;
+
+struct cc33xx_cmd_remove_peer {
+ struct cc33xx_cmd_header header;
+ u8 hlid;
+ u8 role_id;
+ u8 padding[2];
+} __packed;
+
+/* Continuous mode - packets are transferred to the host periodically
+ * via the data path.
+ * On demand - Log messages are stored in a cyclic buffer in the
+ * firmware, and only transferred to the host when explicitly requested
+ */
+enum cc33xx_fwlogger_log_mode {
+ CC33XX_FWLOG_CONTINUOUS,
+};
+
+/* Include/exclude timestamps from the log messages */
+enum cc33xx_fwlogger_timestamp {
+ CC33XX_FWLOG_TIMESTAMP_DISABLED,
+ CC33XX_FWLOG_TIMESTAMP_ENABLED
+};
+
+/* Logs can be routed to the debug pinouts (where available), to the host bus
+ * (SDIO/SPI), or dropped
+ */
+enum cc33xx_fwlogger_output {
+ CC33XX_FWLOG_OUTPUT_NONE,
+ CC33XX_FWLOG_OUTPUT_DBG_PINS,
+ CC33XX_FWLOG_OUTPUT_HOST,
+};
+
+struct cc33xx_cmd_stop_channel_switch {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 padding[3];
+} __packed;
+
+/* Used to check radio status after calibration */
+#define MAX_TLV_LENGTH 500
+#define TEST_CMD_P2G_CAL 2 /* TX BiP */
+
+struct cc33xx_cmd_cal_p2g {
+ struct cc33xx_cmd_header header;
+
+ struct cc33xx_cmd_test_header test;
+
+ __le32 ver;
+ __le16 len;
+ u8 buf[MAX_TLV_LENGTH];
+ u8 type;
+ u8 padding;
+
+ __le16 radio_status;
+
+ u8 sub_band_mask;
+ u8 padding2;
+} __packed;
+
+struct cc33xx_cmd_channel_switch {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+
+ /* The new serving channel */
+ u8 channel;
+ /* Relative time of the serving channel switch in TBTT units */
+ u8 switch_time;
+ /* Stop the role TX, should expect it after radar detection */
+ u8 stop_tx;
+
+ __le32 local_supported_rates;
+
+ u8 channel_type;
+ u8 band;
+
+ u8 padding[2];
+} __packed;
+
+struct cc33xx_cmd_set_bd_addr {
+ struct cc33xx_cmd_header header;
+
+ u8 bd_addr[ETH_ALEN];
+ u8 padding[2];
+} __packed;
+
+/* PLT structs */
+
+struct cc33xx_cmd_PLT_enable {
+ struct cc33xx_cmd_header header;
+ __le32 dummy;
+};
+
+struct cc33xx_cmd_PLT_disable {
+ struct cc33xx_cmd_header header;
+ __le32 dummy;
+};
+
+struct cc33xx_cmd_ini_params_download {
+ struct cc33xx_cmd_header header;
+ __le32 length;
+ u8 payload[];
+} __packed;
+
+struct cc33xx_cmd_container_download {
+ struct cc33xx_cmd_header header;
+ __le32 length;
+ u8 payload[];
+} __packed;
+
+struct cc33xx_cmd_get_device_info {
+ struct cc33xx_cmd_header header;
+ u8 device_info[700];
+} __packed;
+
+#endif /* __CC33XX_CMD_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (4 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:32 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
` (10 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
These file contain various WLAN-oriented APIs
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/acx.c | 767 +++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/acx.h | 827 +++++++++++++++++++++++++++
2 files changed, 1594 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/acx.c
create mode 100644 drivers/net/wireless/ti/cc33xx/acx.h
diff --git a/drivers/net/wireless/ti/cc33xx/acx.c b/drivers/net/wireless/ti/cc33xx/acx.c
new file mode 100644
index 000000000000..b9a56bd26358
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/acx.c
@@ -0,0 +1,767 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "acx.h"
+
+int cc33xx_acx_clear_statistics(struct cc33xx *cc)
+{
+ struct acx_header *acx __free(kfree) = NULL;
+ int ret = 0;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ ret = cc33xx_cmd_configure(cc, ACX_CLEAR_STATISTICS, acx, sizeof(*acx));
+ if (ret < 0)
+ dev_warn(cc->dev, "failed to clear firmware statistics: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_wake_up_conditions(struct cc33xx *cc, u8 wake_up_event,
+ u8 listen_interval)
+{
+ struct acx_wake_up_condition *wake_up __free(kfree) = NULL;
+ int ret;
+
+ wake_up = kzalloc_obj(*wake_up);
+ if (!wake_up)
+ return -ENOMEM;
+
+ wake_up->wake_up_event = wake_up_event;
+ wake_up->listen_interval = listen_interval;
+
+ ret = cc33xx_cmd_configure(cc, WAKE_UP_CONDITIONS_CFG,
+ wake_up, sizeof(*wake_up));
+ if (ret < 0)
+ dev_warn(cc->dev, "could not set wake up conditions: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_sleep_auth(struct cc33xx *cc, u8 sleep_auth)
+{
+ struct acx_sleep_auth *auth __free(kfree) = NULL;
+ int ret;
+
+ auth = kzalloc_obj(*auth);
+ if (!auth)
+ return -ENOMEM;
+
+ auth->sleep_auth = sleep_auth;
+
+ ret = cc33xx_cmd_configure(cc, ACX_SLEEP_AUTH, auth, sizeof(*auth));
+ if (ret < 0) {
+ dev_err(cc->dev, "could not configure sleep_auth to %d: %d\n",
+ sleep_auth, ret);
+ return ret;
+ }
+
+ cc->sleep_auth = sleep_auth;
+
+ return ret;
+}
+
+int cc33xx_acx_tx_power(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ int power)
+{
+ struct acx_tx_power_cfg *acx __free(kfree) = NULL;
+ int ret;
+
+ if (power < CC33XX_MIN_TXPWR) {
+ dev_warn(cc->dev, "Configured Tx power %d dBm. Increasing to minimum %d dBm\n",
+ power, CC33XX_MIN_TXPWR);
+ power = CC33XX_MIN_TXPWR;
+ } else if (power > CC33XX_MAX_TXPWR) {
+ dev_warn(cc->dev, "Configured Tx power %d dBm is bigger than upper limit: %d dBm. Attenuating to max limit\n",
+ power, CC33XX_MAX_TXPWR);
+ power = CC33XX_MAX_TXPWR;
+ }
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->role_id = wlvif->role_id;
+ acx->tx_power = power;
+
+ ret = cc33xx_cmd_configure(cc, TX_POWER_CFG, acx, sizeof(*acx));
+ if (ret < 0) {
+ dev_warn(cc->dev, "Configure of tx power failed: %d\n", ret);
+ return ret;
+ }
+
+ wlvif->power_level = power;
+
+ return ret;
+}
+
+static int cc33xx_acx_mem_map(struct cc33xx *cc,
+ struct acx_header *memory_map, size_t len)
+{
+ int ret;
+
+ ret = cc33xx_cmd_interrogate(cc, MEM_MAP_INTR, memory_map,
+ sizeof(struct acx_header), len);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int cc33xx_acx_get_fw_versions(struct cc33xx *cc,
+ struct cc33xx_acx_fw_versions *get_fw_versions,
+ size_t len)
+{
+ int ret;
+
+ ret = cc33xx_cmd_interrogate(cc, GET_FW_VERSIONS_INTR, get_fw_versions,
+ sizeof(struct cc33xx_acx_fw_versions), len);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+int cc33xx_acx_slot(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum acx_slot_type slot_time)
+{
+ struct acx_slot *slot __free(kfree) = NULL;
+ int ret;
+
+ slot = kzalloc_obj(*slot);
+ if (!slot)
+ return -ENOMEM;
+
+ slot->role_id = wlvif->role_id;
+ slot->slot_time = slot_time;
+
+ ret = cc33xx_cmd_configure(cc, SLOT_CFG, slot, sizeof(*slot));
+ if (ret < 0)
+ dev_warn(cc->dev, "failed to set slot time: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_group_address_tbl(struct cc33xx *cc, bool enable, void *mc_list, u32 mc_list_len)
+{
+ struct acx_dot11_grp_addr_tbl *acx __free(kfree) = NULL;
+ int ret;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->enabled = enable;
+ acx->num_groups = mc_list_len;
+ memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
+
+ ret = cc33xx_cmd_configure(cc, DOT11_GROUP_ADDRESS_TBL,
+ acx, sizeof(*acx));
+ if (ret < 0)
+ dev_warn(cc->dev, "failed to set group addr table: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_beacon_filter_opt(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ bool enable_filter)
+{
+ struct acx_beacon_filter_option *beacon_filter __free(kfree) = NULL;
+ int ret = 0;
+
+ if (enable_filter &&
+ cc->conf.host_conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
+ return 0;
+
+ beacon_filter = kzalloc_obj(*beacon_filter);
+ if (!beacon_filter)
+ return -ENOMEM;
+
+ beacon_filter->role_id = wlvif->role_id;
+ beacon_filter->enable = enable_filter;
+
+ /* When set to zero, and the filter is enabled, beacons
+ * without the unicast TIM bit set are dropped.
+ */
+ beacon_filter->max_num_beacons = 0;
+
+ ret = cc33xx_cmd_configure(cc, BEACON_FILTER_OPT,
+ beacon_filter, sizeof(*beacon_filter));
+ if (ret < 0)
+ dev_warn(cc->dev, "failed to set beacon filter opt: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_beacon_filter_table(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct acx_beacon_filter_ie_table *ie_table __free(kfree) = NULL;
+ struct conf_bcn_filt_rule *r = &cc->conf.host_conf.conn.bcn_filt_ie0;
+ struct conf_bcn_filt_rule *itr_end;
+ int idx = 0;
+ int ret;
+ bool vendor_spec = false;
+
+ if (WARN_ON(cc->conf.host_conf.conn.bcn_filt_ie_count > CONF_MAX_BCN_FILT_IE_COUNT))
+ return -EINVAL;
+
+ itr_end = r + cc->conf.host_conf.conn.bcn_filt_ie_count;
+
+ ie_table = kzalloc_obj(*ie_table);
+ if (!ie_table)
+ return -ENOMEM;
+
+ /* configure default beacon pass-through rules */
+ ie_table->role_id = wlvif->role_id;
+ ie_table->num_ie = 0;
+
+ while (r < itr_end) {
+ ie_table->table[idx++] = r->ie;
+ ie_table->table[idx++] = r->rule;
+
+ /* only one vendor specific ie allowed */
+ if (r->ie == WLAN_EID_VENDOR_SPECIFIC && !vendor_spec) {
+ /* for vendor specific rules configure the
+ * additional fields
+ */
+ memcpy(&ie_table->table[idx], r->oui,
+ CONF_BCN_IE_OUI_LEN);
+ idx += CONF_BCN_IE_OUI_LEN;
+ ie_table->table[idx++] = r->type;
+ memcpy(&ie_table->table[idx], r->version,
+ CONF_BCN_IE_VER_LEN);
+ idx += CONF_BCN_IE_VER_LEN;
+ vendor_spec = true;
+ }
+
+ ie_table->num_ie++;
+ r++;
+ }
+
+ ret = cc33xx_cmd_configure(cc, BEACON_FILTER_TABLE,
+ ie_table, sizeof(*ie_table));
+ if (ret < 0)
+ dev_warn(cc->dev, "failed to set beacon filter table: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_assoc_info_cfg(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta, u16 aid)
+{
+ struct assoc_info_cfg *cfg __free(kfree) = NULL;
+ int ret;
+
+ cfg = kzalloc_obj(*cfg);
+ if (!cfg)
+ return -ENOMEM;
+
+ cfg->role_id = wlvif->role_id;
+ cfg->aid = cpu_to_le16(aid);
+ cfg->wmm_enabled = wlvif->wmm_enabled;
+
+ cfg->nontransmitted = wlvif->nontransmitted;
+ cfg->bssid_index = wlvif->bssid_index;
+ cfg->bssid_indicator = wlvif->bssid_indicator;
+ cfg->ht_supported = sta->deflink.ht_cap.ht_supported;
+ cfg->vht_supported = sta->deflink.vht_cap.vht_supported;
+ cfg->has_he = sta->deflink.he_cap.has_he;
+ memcpy(cfg->transmitter_bssid, wlvif->transmitter_bssid, ETH_ALEN);
+ ret = cc33xx_cmd_configure(cc, ASSOC_INFO_CFG, cfg, sizeof(*cfg));
+ if (ret < 0)
+ dev_warn(cc->dev, "failed to set aid: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_set_preamble(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum acx_preamble_type preamble)
+{
+ struct acx_preamble *acx __free(kfree) = NULL;
+ int ret;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->role_id = wlvif->role_id;
+ acx->preamble = preamble;
+
+ ret = cc33xx_cmd_configure(cc, PREAMBLE_TYPE_CFG, acx, sizeof(*acx));
+ if (ret < 0)
+ dev_warn(cc->dev, "Setting of preamble failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_cts_protect(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum acx_ctsprotect_type ctsprotect)
+{
+ struct acx_ctsprotect *acx __free(kfree) = NULL;
+ int ret;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->role_id = wlvif->role_id;
+ acx->ctsprotect = ctsprotect;
+
+ ret = cc33xx_cmd_configure(cc, CTS_PROTECTION_CFG, acx, sizeof(*acx));
+ if (ret < 0)
+ dev_warn(cc->dev, "Setting of ctsprotect failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_statistics(struct cc33xx *cc, void *stats)
+{
+ int ret;
+
+ ret = cc33xx_cmd_interrogate(cc, ACX_STATISTICS, stats,
+ sizeof(struct acx_header),
+ sizeof(struct cc33xx_acx_statistics));
+ if (ret < 0) {
+ dev_warn(cc->dev, "acx statistics failed: %d\n", ret);
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+int cc33xx_update_ap_rates(struct cc33xx *cc, u8 role_id,
+ u32 basic_rates_set, u32 supported_rates)
+{
+ struct ap_rates_class_cfg *cfg __free(kfree) = NULL;
+ int ret;
+
+ cfg = kzalloc_obj(*cfg);
+ if (!cfg)
+ return -ENOMEM;
+
+ cfg->basic_rates_set = cpu_to_le32(basic_rates_set);
+ cfg->supported_rates = cpu_to_le32(supported_rates);
+ cfg->role_id = role_id;
+ ret = cc33xx_cmd_configure(cc, AP_RATES_CFG, cfg, sizeof(*cfg));
+ if (ret < 0)
+ dev_warn(cc->dev, "Updating AP Rates failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_tx_param_cfg(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 ac,
+ u8 cw_min, u16 cw_max, u8 aifsn, u16 txop, bool acm,
+ u8 ps_scheme, u8 is_mu_edca, u8 mu_edca_aifs,
+ u8 mu_edca_ecw_min_max, u8 mu_edca_timer)
+{
+ struct tx_param_cfg *cfg __free(kfree) = NULL;
+ int ret = 0;
+
+ cfg = kzalloc_obj(*cfg);
+
+ if (!cfg)
+ return -ENOMEM;
+
+ cfg->role_id = wlvif->role_id;
+ cfg->ac = ac;
+ cfg->cw_min = cw_min;
+ cfg->cw_max = cpu_to_le16(cw_max);
+ cfg->aifsn = aifsn;
+ cfg->tx_op_limit = cpu_to_le16(txop);
+ cfg->acm = cpu_to_le16(acm);
+ cfg->ps_scheme = ps_scheme;
+ cfg->is_mu_edca = is_mu_edca;
+ cfg->mu_edca_aifs = mu_edca_aifs;
+ cfg->mu_edca_ecw_min_max = mu_edca_ecw_min_max;
+ cfg->mu_edca_timer = mu_edca_timer;
+
+ ret = cc33xx_cmd_configure(cc, TX_PARAMS_CFG, cfg, sizeof(*cfg));
+ if (ret < 0)
+ dev_warn(cc->dev, "tx param cfg failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_init_mem_config(struct cc33xx *cc)
+{
+ int ret;
+
+ cc->target_mem_map = kzalloc_obj(*cc->target_mem_map);
+ if (!cc->target_mem_map) {
+ dev_err(cc->dev, "couldn't allocate target memory map\n");
+ return -ENOMEM;
+ }
+
+ /* we now ask for the firmware built memory map */
+ ret = cc33xx_acx_mem_map(cc, (void *)cc->target_mem_map,
+ sizeof(struct cc33xx_acx_mem_map));
+ if (ret < 0) {
+ dev_err(cc->dev, "couldn't retrieve firmware memory map\n");
+ kfree(cc->target_mem_map);
+ cc->target_mem_map = NULL;
+ return ret;
+ }
+
+ /* initialize TX block book keeping */
+ cc->tx_blocks_available =
+ le32_to_cpu(cc->target_mem_map->num_tx_mem_blocks);
+
+ return 0;
+}
+
+int cc33xx_acx_init_get_fw_versions(struct cc33xx *cc)
+{
+ int ret;
+
+ struct cc33xx_acx_fw_versions *fw_ver __free(kfree) = NULL;
+
+ fw_ver = kzalloc_obj(*fw_ver);
+ if (!fw_ver) {
+ dev_err(cc->dev, "couldn't allocate cc33xx_acx_fw_versions\n");
+ return -ENOMEM;
+ }
+
+ ret = cc33xx_acx_get_fw_versions(cc, fw_ver,
+ sizeof(struct cc33xx_acx_fw_versions));
+ if (ret < 0) {
+ dev_err(cc->dev, "couldn't retrieve firmware versions\n");
+ return ret;
+ }
+
+ cc->fw_ver.major_version = le16_to_cpu(fw_ver->major_version);
+ cc->fw_ver.minor_version = le16_to_cpu(fw_ver->minor_version);
+ cc->fw_ver.api_version = le16_to_cpu(fw_ver->api_version);
+ cc->fw_ver.build_version = le16_to_cpu(fw_ver->build_version);
+
+ memcpy(cc->fw_ver.phy_version, fw_ver->phy_version,
+ sizeof(cc->fw_ver.phy_version));
+
+ return 0;
+}
+
+int cc33xx_acx_set_ht_information(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 ht_operation_mode, u32 he_oper_params,
+ u16 he_oper_nss_set)
+{
+ struct cc33xx_acx_ht_information *acx __free(kfree) = NULL;
+ int ret = 0;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->role_id = wlvif->role_id;
+ acx->ht_protection =
+ (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
+ acx->rifs_mode = 0;
+ acx->gf_protection =
+ !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
+
+ acx->dual_cts_protection = 0;
+
+ acx->he_operation = cpu_to_le32(he_oper_params);
+ acx->bss_basic_mcs_set = cpu_to_le16(he_oper_nss_set);
+ acx->qos_info_more_data_ack_bit = 0;
+ ret = cc33xx_cmd_configure(cc, BSS_OPERATION_CFG, acx, sizeof(*acx));
+
+ if (ret < 0)
+ dev_warn(cc->dev, "acx ht information setting failed: %d\n", ret);
+
+ return ret;
+}
+
+/* setup BA session receiver setting in the FW. */
+int cc33xx_acx_set_ba_receiver_session(struct cc33xx *cc, u8 tid_index, u16 ssn,
+ bool enable, u8 peer_hlid, u8 win_size)
+{
+ struct cc33xx_acx_ba_receiver_setup *acx __free(kfree) = NULL;
+ int ret;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->hlid = peer_hlid;
+ acx->tid = tid_index;
+ acx->enable = enable;
+ acx->win_size = win_size;
+ acx->ssn = cpu_to_le16(ssn);
+
+ ret = cc33xx_cmd_configure_failsafe(cc, BA_SESSION_RX_SETUP_CFG,
+ acx, sizeof(*acx),
+ BIT(CMD_STATUS_NO_RX_BA_SESSION));
+ if (ret < 0) {
+ dev_warn(cc->dev, "acx ba receiver session failed: %d\n", ret);
+ return ret;
+ }
+
+ /* sometimes we can't start the session */
+ if (ret == CMD_STATUS_NO_RX_BA_SESSION) {
+ dev_warn(cc->dev, "no fw rx ba on tid %d\n", tid_index);
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+int cc33xx_acx_config_ps(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct cc33xx_acx_config_ps *config_ps __free(kfree) = NULL;
+ int ret;
+
+ config_ps = kzalloc_obj(*config_ps);
+ if (!config_ps)
+ return -ENOMEM;
+
+ config_ps->exit_retries = cc->conf.host_conf.conn.psm_exit_retries;
+ config_ps->enter_retries = cc->conf.host_conf.conn.psm_entry_retries;
+ config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
+
+ ret = cc33xx_cmd_configure(cc, ACX_CONFIG_PS, config_ps,
+ sizeof(*config_ps));
+ if (ret < 0)
+ dev_warn(cc->dev, "acx config ps failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_average_rssi(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, s8 *avg_rssi)
+{
+ struct acx_roaming_stats *acx __free(kfree) = NULL;
+ int ret = 0;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->role_id = wlvif->role_id;
+
+ ret = cc33xx_cmd_interrogate(cc, RSSI_INTR,
+ acx, sizeof(*acx), sizeof(*acx));
+ if (ret < 0) {
+ dev_warn(cc->dev, "acx roaming statistics failed: %d\n", ret);
+ return ret;
+ }
+
+ *avg_rssi = acx->rssi_beacon;
+
+ return ret;
+}
+
+static const u16 cc33xx_idx_to_rate_100kbps[] = {
+ 10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540
+};
+
+int cc33xx_acx_get_tx_rate(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct station_info *sinfo)
+{
+ struct acx_preamble_and_tx_rate *acx __free(kfree) = NULL;
+ int ret;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->role_id = wlvif->role_id;
+
+ ret = cc33xx_cmd_interrogate(cc, GET_PREAMBLE_AND_TX_RATE_INTR,
+ acx, sizeof(*acx), sizeof(*acx));
+ if (ret < 0) {
+ dev_warn(cc->dev, "acx get preamble and tx rate failed: %d\n", ret);
+ return ret;
+ }
+
+ sinfo->txrate.flags = 0;
+ if (acx->preamble == CONF_PREAMBLE_TYPE_AC_VHT)
+ sinfo->txrate.flags = RATE_INFO_FLAGS_VHT_MCS;
+ else if ((acx->preamble >= CONF_PREAMBLE_TYPE_AX_SU) &&
+ (acx->preamble <= CONF_PREAMBLE_TYPE_AX_TB_NDP_FB))
+ sinfo->txrate.flags = RATE_INFO_FLAGS_HE_MCS;
+ else if ((acx->preamble == CONF_PREAMBLE_TYPE_N_MIXED_MODE) ||
+ (acx->preamble == CONF_PREAMBLE_TYPE_GREENFIELD))
+ sinfo->txrate.flags = RATE_INFO_FLAGS_MCS;
+
+ if (acx->tx_rate >= CONF_HW_RATE_INDEX_MCS0)
+ sinfo->txrate.mcs = acx->tx_rate - CONF_HW_RATE_INDEX_MCS0;
+ else
+ sinfo->txrate.legacy = cc33xx_idx_to_rate_100kbps[acx->tx_rate - 1];
+
+ sinfo->txrate.nss = 1;
+ sinfo->txrate.bw = RATE_INFO_BW_20;
+ sinfo->txrate.he_gi = NL80211_RATE_INFO_HE_GI_3_2;
+ sinfo->txrate.he_dcm = 0;
+ sinfo->txrate.he_ru_alloc = 0;
+ sinfo->txrate.n_bonded_ch = 0;
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
+
+ return ret;
+}
+
+#ifdef CONFIG_PM
+/* Set the global behaviour of RX filters - On/Off + default action */
+int cc33xx_acx_default_rx_filter_enable(struct cc33xx *cc, bool enable,
+ enum rx_filter_action action)
+{
+ struct acx_default_rx_filter *acx __free(kfree) = NULL;
+ int ret;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->enable = enable;
+ acx->default_action = action;
+ acx->special_packet_bitmask = 0;
+
+ ret = cc33xx_cmd_configure(cc, ACX_ENABLE_RX_DATA_FILTER, acx,
+ sizeof(*acx));
+ if (ret < 0)
+ dev_warn(cc->dev, "acx default rx filter enable failed: %d\n", ret);
+
+ return ret;
+}
+
+static int cc33xx_rx_filter_get_fields_size(struct cc33xx_rx_filter *filter)
+{
+ int i, fields_size = 0;
+
+ for (i = 0; i < filter->num_fields; i++) {
+ fields_size += filter->fields[i].len - sizeof(u8 *)
+ + sizeof(struct cc33xx_rx_filter_field);
+ }
+
+ return fields_size;
+}
+
+static void cc33xx_rx_filter_flatten_fields(struct cc33xx_rx_filter *filter,
+ u8 *buf)
+{
+ int i;
+ struct cc33xx_rx_filter_field *field;
+
+ for (i = 0; i < filter->num_fields; i++) {
+ field = (struct cc33xx_rx_filter_field *)buf;
+
+ field->offset = filter->fields[i].offset;
+ field->flags = filter->fields[i].flags;
+ field->len = filter->fields[i].len;
+
+ memcpy(&field->pattern, filter->fields[i].pattern, field->len);
+ buf += sizeof(struct cc33xx_rx_filter_field) - sizeof(u8 *);
+ buf += field->len;
+ }
+}
+
+/* Configure or disable a specific RX filter pattern */
+int cc33xx_acx_set_rx_filter(struct cc33xx *cc, u8 index, bool enable,
+ struct cc33xx_rx_filter *filter)
+{
+ struct acx_rx_filter_cfg *acx __free(kfree) = NULL;
+ int fields_size = 0;
+ int acx_size;
+ int ret;
+
+ WARN_ON(enable && !filter);
+ WARN_ON(index >= CC33XX_MAX_RX_FILTERS);
+
+ if (enable)
+ fields_size = cc33xx_rx_filter_get_fields_size(filter);
+
+ acx_size = ALIGN(sizeof(*acx) + fields_size, 4);
+ acx = kzalloc(acx_size, GFP_KERNEL);
+ if (!acx)
+ return -ENOMEM;
+
+ acx->enable = enable;
+ acx->index = index;
+
+ if (enable) {
+ acx->num_fields = filter->num_fields;
+ acx->action = filter->action;
+ cc33xx_rx_filter_flatten_fields(filter, acx->fields);
+ }
+
+ cc33xx_dump(DEBUG_ACX, "RX_FILTER: ", acx, acx_size);
+
+ ret = cc33xx_cmd_configure(cc, ACX_SET_RX_DATA_FILTER, acx, acx_size);
+ if (ret < 0)
+ dev_warn(cc->dev, "setting rx filter failed: %d\n", ret);
+
+ return ret;
+}
+#endif /* CONFIG_PM */
+
+/* this command is basically the same as cc33xx_acx_ht_capabilities,
+ * with the addition of supported rates. they should be unified in
+ * the next fw api change
+ */
+int cc33xx_acx_set_peer_cap(struct cc33xx *cc,
+ struct ieee80211_sta_ht_cap *ht_cap,
+ struct ieee80211_sta_he_cap *he_cap,
+ struct cc33xx_vif *wlvif, bool allow_ht_operation,
+ u32 rate_set)
+{
+ struct cc33xx_acx_peer_cap *acx __free(kfree) = NULL;
+ int ret = 0;
+ u32 ht_capabilites = 0;
+ u8 *cap_info = NULL;
+ u8 dcm_max_const_rx_mask = IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
+ u8 partial_bw_ext_range = IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE;
+
+ acx = kzalloc_obj(*acx);
+ if (!acx)
+ return -ENOMEM;
+
+ if (allow_ht_operation && ht_cap->ht_supported) {
+ /* no need to translate capabilities - use the spec values */
+ ht_capabilites = ht_cap->cap;
+
+ /* this bit is not employed by the spec but only by FW to
+ * indicate peer HT support
+ */
+ ht_capabilites |= CC33XX_HT_CAP_HT_OPERATION;
+
+ /* get data from A-MPDU parameters field */
+ acx->ampdu_max_length = ht_cap->ampdu_factor;
+ acx->ampdu_min_spacing = ht_cap->ampdu_density;
+ }
+
+ acx->ht_capabilites = cpu_to_le32(ht_capabilites);
+ acx->supported_rates = cpu_to_le32(rate_set);
+
+ acx->role_id = wlvif->role_id;
+ acx->has_he = he_cap->has_he;
+ memcpy(acx->mac_cap_info, he_cap->he_cap_elem.mac_cap_info, 6);
+ cap_info = he_cap->he_cap_elem.phy_cap_info;
+ acx->nominal_packet_padding = (cap_info[8] & NOMINAL_PACKET_PADDING);
+ /* Max DCM constelation for RX - bits [4:3] in PHY capabilities byte 3 */
+ acx->dcm_max_constelation = (cap_info[3] & dcm_max_const_rx_mask) >> 3;
+ acx->er_upper_supported = ((cap_info[6] & partial_bw_ext_range) != 0);
+ ret = cc33xx_cmd_configure(cc, PEER_CAP_CFG, acx, sizeof(*acx));
+
+ if (ret < 0)
+ dev_warn(cc->dev, "acx ht capabilities setting failed: %d\n", ret);
+
+ return ret;
+}
+
+int cc33xx_acx_trigger_fw_assert(struct cc33xx *cc)
+{
+ struct debug_header *buf __free(kfree) = NULL;
+ int ret;
+
+ buf = kzalloc_obj(*buf);
+ if (!buf)
+ return -ENOMEM;
+
+ ret = cc33xx_cmd_debug(cc, TRIGGER_FW_ASSERT, buf, sizeof(*buf));
+ if (ret < 0)
+ dev_err(cc->dev, "failed to trigger firmware assert\n");
+
+ return ret;
+}
diff --git a/drivers/net/wireless/ti/cc33xx/acx.h b/drivers/net/wireless/ti/cc33xx/acx.h
new file mode 100644
index 000000000000..43b6c4b16c57
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/acx.h
@@ -0,0 +1,827 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __ACX_H__
+#define __ACX_H__
+
+#include "cmd.h"
+#include "debug.h"
+
+enum {
+ /* Regular PS: simple sending of packets */
+ PS_SCHEME_LEGACY = 0,
+ /* UPSD: sending a packet triggers a UPSD downstream*/
+ PS_SCHEME_UPSD_TRIGGER = 1,
+ /* Mixed mode is partially supported: we are not going to sleep, and
+ * triggers (on APSD AC's) are not sent when service period ends with
+ * more_data = 1.
+ */
+ PS_SCHEME_MIXED_MODE = 2,
+ /* Legacy PSPOLL: a PSPOLL packet will be sent before every data packet
+ * transmission in this queue.
+ */
+ PS_SCHEME_LEGACY_PSPOLL = 3,
+ /* Scheduled APSD mode. */
+ PS_SCHEME_SAPSD = 4,
+ /* No PSPOLL: move to active after first packet. no need to sent pspoll */
+ PS_SCHEME_NOPSPOLL = 5,
+
+ MAX_PS_SCHEME = PS_SCHEME_NOPSPOLL
+};
+
+/* Target's information element */
+struct acx_header {
+ struct cc33xx_cmd_header cmd;
+
+ /* acx (or information element) header */
+ __le16 id;
+
+ /* payload length (not including headers */
+ __le16 len;
+} __packed;
+
+struct debug_header {
+ struct cc33xx_cmd_header cmd;
+
+ /* debug (or information element) header */
+ __le16 id;
+
+ /* payload length (not including headers */
+ __le16 len;
+} __packed;
+
+enum cc33xx_role {
+ CC33XX_ROLE_STA = 0,
+ CC33XX_ROLE_IBSS,
+ CC33XX_ROLE_AP,
+ CC33XX_ROLE_DEVICE,
+ CC33XX_ROLE_P2P_CL,
+ CC33XX_ROLE_P2P_GO,
+ CC33XX_ROLE_MESH_POINT,
+
+ ROLE_TRANSCEIVER = 16,
+
+ CC33XX_INVALID_ROLE_TYPE = 0xff
+};
+
+enum cc33xx_psm_mode {
+ /* Active mode */
+ CC33XX_PSM_CAM = 0,
+
+ /* Power save mode */
+ CC33XX_PSM_PS = 1,
+
+ /* Extreme low power */
+ CC33XX_PSM_ELP = 2,
+
+ CC33XX_PSM_MAX = CC33XX_PSM_ELP,
+
+ /* illegal out of band value of PSM mode */
+ CC33XX_PSM_ILLEGAL = 0xff
+};
+
+struct acx_sleep_auth {
+ struct acx_header header;
+
+ /* The sleep level authorization of the device. */
+ /* 0 - Always active*/
+ /* 1 - Power down mode: light / fast sleep*/
+ /* 2 - ELP mode: Deep / Max sleep*/
+ u8 sleep_auth;
+ u8 padding[3];
+} __packed;
+
+enum acx_slot_type {
+ SLOT_TIME_LONG = 0,
+ SLOT_TIME_SHORT = 1,
+ DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
+ MAX_SLOT_TIMES = 0xFF
+};
+
+struct acx_slot {
+ struct acx_header header;
+
+ u8 role_id;
+ u8 slot_time;
+ u8 reserved[2];
+} __packed;
+
+#define ACX_MC_ADDRESS_GROUP_MAX (20)
+#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ACX_MC_ADDRESS_GROUP_MAX)
+
+struct acx_dot11_grp_addr_tbl {
+ struct acx_header header;
+
+ u8 enabled;
+ u8 num_groups;
+ u8 pad[2];
+ u8 mac_table[ADDRESS_GROUP_MAX_LEN];
+} __packed;
+
+struct acx_beacon_filter_option {
+ struct acx_header header;
+
+ u8 role_id;
+ u8 enable;
+ /* The number of beacons without the unicast TIM
+ * bit set that the firmware buffers before
+ * signaling the host about ready frames.
+ * When set to 0 and the filter is enabled, beacons
+ * without the unicast TIM bit set are dropped.
+ */
+ u8 max_num_beacons;
+ u8 pad;
+} __packed;
+
+/* ACXBeaconFilterEntry (not 221)
+ * Byte Offset Size (Bytes) Definition
+ * =========== ============ ==========
+ * 0 1 IE identifier
+ * 1 1 Treatment bit mask
+ *
+ * ACXBeaconFilterEntry (221)
+ * Byte Offset Size (Bytes) Definition
+ * =========== ============ ==========
+ * 0 1 IE identifier
+ * 1 1 Treatment bit mask
+ * 2 3 OUI
+ * 5 1 Type
+ * 6 2 Version
+ *
+ *
+ * Treatment bit mask - The information element handling:
+ * bit 0 - The information element is compared and transferred
+ * in case of change.
+ * bit 1 - The information element is transferred to the host
+ * with each appearance or disappearance.
+ * Note that both bits can be set at the same time.
+ */
+
+enum {
+ BEACON_FILTER_TABLE_MAX_IE_NUM = 32,
+ BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM = 6,
+ BEACON_FILTER_TABLE_IE_ENTRY_SIZE = 2,
+ BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE = 6
+};
+
+#define BEACON_FILTER_TABLE_MAX_SIZE \
+ ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
+ BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
+ (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
+ BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
+
+struct acx_beacon_filter_ie_table {
+ struct acx_header header;
+
+ u8 role_id;
+ u8 num_ie;
+ u8 pad[2];
+ u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
+} __packed;
+
+struct acx_energy_detection {
+ struct acx_header header;
+
+ /* The RX Clear Channel Assessment threshold in the PHY */
+ __le16 rx_cca_threshold;
+ u8 tx_energy_detection;
+ u8 pad;
+} __packed;
+
+struct acx_event_mask {
+ struct acx_header header;
+
+ __le32 event_mask;
+ __le32 high_event_mask; /* Unused */
+} __packed;
+
+struct acx_tx_power_cfg {
+ struct acx_header header;
+
+ u8 role_id;
+ s8 tx_power;
+ u8 padding[2];
+} __packed;
+
+struct acx_wake_up_condition {
+ struct acx_header header;
+
+ u8 wake_up_event;
+ u8 listen_interval;
+ u8 padding[2];
+} __packed;
+
+struct assoc_info_cfg {
+ struct acx_header header;
+
+ u8 role_id;
+ __le16 aid;
+ u8 wmm_enabled;
+ u8 nontransmitted;
+ u8 bssid_index;
+ u8 bssid_indicator;
+ u8 transmitter_bssid[ETH_ALEN];
+ u8 ht_supported;
+ u8 vht_supported;
+ u8 has_he;
+} __packed;
+
+enum acx_preamble_type {
+ ACX_PREAMBLE_LONG = 0,
+ ACX_PREAMBLE_SHORT = 1
+};
+
+struct acx_preamble {
+ struct acx_header header;
+
+ /* When set, the WiLink transmits the frames with a short preamble and
+ * when cleared, the WiLink transmits the frames with a long preamble.
+ */
+ u8 role_id;
+ u8 preamble;
+ u8 padding[2];
+} __packed;
+
+enum acx_ctsprotect_type {
+ CTSPROTECT_DISABLE = 0,
+ CTSPROTECT_ENABLE = 1
+};
+
+struct acx_ctsprotect {
+ struct acx_header header;
+ u8 role_id;
+ u8 ctsprotect;
+ u8 padding[2];
+} __packed;
+
+struct ap_rates_class_cfg {
+ struct acx_header header;
+ u8 role_id;
+ __le32 basic_rates_set;
+ __le32 supported_rates;
+ u8 padding[3];
+} __packed;
+
+struct tx_param_cfg {
+ struct acx_header header;
+
+ u8 role_id;
+ u8 ac;
+ u8 aifsn;
+ u8 cw_min;
+
+ __le16 cw_max;
+ __le16 tx_op_limit;
+
+ __le16 acm;
+
+ u8 ps_scheme;
+
+ u8 is_mu_edca;
+ u8 mu_edca_aifs;
+ u8 mu_edca_ecw_min_max;
+ u8 mu_edca_timer;
+
+ u8 reserved;
+} __packed;
+
+struct cc33xx_acx_config_memory {
+ struct acx_header header;
+
+ u8 rx_mem_block_num;
+ u8 tx_min_mem_block_num;
+ u8 num_stations;
+ u8 num_ssid_profiles;
+ __le32 total_tx_descriptors;
+ u8 dyn_mem_enable;
+ u8 tx_free_req;
+ u8 rx_free_req;
+ u8 tx_min;
+ u8 fwlog_blocks;
+ u8 padding[3];
+} __packed;
+
+struct cc33xx_acx_mem_map {
+ struct acx_header header;
+
+ /* Number of blocks FW allocated for TX packets */
+ __le32 num_tx_mem_blocks;
+
+ /* Number of blocks FW allocated for RX packets */
+ __le32 num_rx_mem_blocks;
+
+ /* Number of TX descriptor that allocated. */
+ __le32 num_tx_descriptor;
+
+ __le32 tx_result;
+
+} __packed;
+
+struct cc33xx_acx_fw_versions {
+ struct acx_header header;
+
+ __le16 major_version;
+ __le16 minor_version;
+ __le16 api_version;
+ __le16 build_version;
+
+ u8 phy_version[6];
+ u8 padding[2];
+} __packed;
+
+/* special capability bit (not employed by the 802.11n spec) */
+#define CC33XX_HT_CAP_HT_OPERATION BIT(16)
+
+/* ACX_HT_BSS_OPERATION
+ * Configure HT capabilities - AP rules for behavior in the BSS.
+ */
+struct cc33xx_acx_ht_information {
+ struct acx_header header;
+
+ u8 role_id;
+
+ /* Values: 0 - RIFS not allowed, 1 - RIFS allowed */
+ u8 rifs_mode;
+
+ /* Values: 0 - 3 like in spec */
+ u8 ht_protection;
+
+ /* Values: 0 - GF protection not required, 1 - GF protection required */
+ u8 gf_protection;
+
+ /* Values: 0 - Dual CTS protection not required,
+ * 1 - Dual CTS Protection required
+ * Note: When this value is set to 1 FW will protect all TXOP with RTS
+ * frame and will not use CTS-to-self regardless of the value of the
+ * ACX_CTS_PROTECTION information element
+ */
+ u8 dual_cts_protection;
+
+ __le32 he_operation;
+
+ __le16 bss_basic_mcs_set;
+ u8 qos_info_more_data_ack_bit;
+
+} __packed;
+
+struct cc33xx_acx_ba_receiver_setup {
+ struct acx_header header;
+
+ /* Specifies link id, range 0-31 */
+ u8 hlid;
+
+ u8 tid;
+
+ u8 enable;
+
+ /* Windows size in number of packets */
+ u8 win_size;
+
+ /* BA session starting sequence number. RANGE 0-FFF */
+ __le16 ssn;
+
+ u8 padding[2];
+} __packed;
+
+struct cc33xx_acx_fw_tsf_information {
+ struct acx_header header;
+
+ u8 role_id;
+ u8 padding1[3];
+ __le32 current_tsf_high;
+ __le32 current_tsf_low;
+ __le32 last_bttt_high;
+ __le32 last_tbtt_low;
+ u8 last_dtim_count;
+ u8 padding2[3];
+} __packed;
+
+struct cc33xx_acx_config_ps {
+ struct acx_header header;
+
+ u8 exit_retries;
+ u8 enter_retries;
+ u8 padding[2];
+ __le32 null_data_rate;
+} __packed;
+
+#define ACX_RATE_MGMT_ALL_PARAMS 0xff
+
+struct acx_default_rx_filter {
+ struct acx_header header;
+ u8 enable;
+
+ /* action of type FILTER_XXX */
+ u8 default_action;
+
+ /* special packet bitmask - packet that use for trigger the host */
+ u8 special_packet_bitmask;
+
+ u8 padding;
+} __packed;
+
+struct acx_rx_filter_cfg {
+ struct acx_header header;
+
+ u8 enable;
+
+ /* 0 - CC33XX_MAX_RX_FILTERS-1 */
+ u8 index;
+
+ u8 action;
+
+ u8 num_fields;
+ u8 fields[];
+} __packed;
+
+struct acx_roaming_stats {
+ struct acx_header header;
+
+ u8 role_id;
+ u8 pad[3];
+ __le32 missed_beacons;
+ u8 snr_data;
+ u8 snr_bacon;
+ s8 rssi_data;
+ s8 rssi_beacon;
+} __packed;
+
+enum cfg {
+ CTS_PROTECTION_CFG = 0,
+ TX_PARAMS_CFG = 1,
+ ASSOC_INFO_CFG = 2,
+ PEER_CAP_CFG = 3,
+ BSS_OPERATION_CFG = 4,
+ SLOT_CFG = 5,
+ PREAMBLE_TYPE_CFG = 6,
+ DOT11_GROUP_ADDRESS_TBL = 7,
+ BA_SESSION_RX_SETUP_CFG = 8,
+ ACX_SLEEP_AUTH = 9,
+ STATIC_CALIBRATION_CFG = 10,
+ AP_RATES_CFG = 11,
+ WAKE_UP_CONDITIONS_CFG = 12,
+ SET_ANTENNA_SELECT_CFG = 13,
+ TX_POWER_CFG = 14,
+ VENDOR_IE_CFG = 15,
+ START_COEX_STATISTICS_CFG = 16,
+ BEACON_FILTER_OPT = 17,
+ BEACON_FILTER_TABLE = 18,
+ ACX_ENABLE_RX_DATA_FILTER = 19,
+ ACX_SET_RX_DATA_FILTER = 20,
+ ACX_GET_DATA_FILTER_STATISTICS = 21,
+ TWT_SETUP = 22,
+ TWT_TERMINATE = 23,
+ TWT_SUSPEND = 24,
+ TWT_RESUME = 25,
+ ANT_DIV_ENABLE = 26,
+ ANT_DIV_SET_RSSI_THRESHOLD = 27,
+ ANT_DIV_SELECT_DEFAULT_ANTENNA = 28,
+
+ LAST_CFG_VALUE,
+ MAX_DOT11_CFG = LAST_CFG_VALUE,
+
+ MAX_CFG = 0xFFFF /*force enumeration to 16bits*/
+};
+
+enum cmd_debug {
+ UPLINK_MULTI_USER_CFG,
+ UPLINK_MULTI_USER_DATA_CFG,
+ OPERATION_MODE_CTRL_CFG,
+ UPLINK_POWER_HEADER_CFG,
+ MCS_FIXED_RATE_CFG,
+ GI_LTF_CFG,
+ TRANSMIT_OMI_CFG,
+ TB_ONLY_CFG,
+ BA_SESSION_CFG,
+ FORCE_PS_CFG,
+ RATE_OVERRRIDE_CFG,
+ BLS_CFG,
+ BLE_ENABLE,
+ SET_TSF,
+ RTS_TH_CFG,
+ LINK_ADAPT_CFG,
+ CALIB_BITMAP_CFG,
+ PWR_PARTIAL_MODES_CFG,
+ TRIGGER_FW_ASSERT,
+ BURST_MODE_CFG,
+
+ LAST_DEBUG_VALUE,
+
+ MAX_DEBUG = 0xFFFF /*force enumeration to 16bits*/
+
+};
+
+enum interrogate_opt {
+ MEM_MAP_INTR = 0,
+ GET_FW_VERSIONS_INTR = 1,
+ RSSI_INTR = 2,
+ GET_ANTENNA_SELECT_INTR = 3,
+ GET_PREAMBLE_AND_TX_RATE_INTR = 4,
+ GET_MAC_ADDRESS = 5,
+ READ_COEX_STATISTICS = 6,
+ LAST_IE_VALUE,
+ MAX_DOT11_IE = LAST_IE_VALUE,
+
+ MAX_IE = 0xFFFF /*force enumeration to 16bits*/
+};
+
+enum {
+ ACX_STATISTICS = LAST_CFG_VALUE,
+ ACX_CONFIG_PS,
+ ACX_CLEAR_STATISTICS = 0x0054,
+};
+
+struct cc33xx_acx_error_stats {
+ __le32 error_frame_non_ctrl;
+ __le32 error_frame_ctrl;
+ __le32 error_frame_during_protection;
+ __le32 null_frame_tx_start;
+ __le32 null_frame_cts_start;
+ __le32 bar_retry;
+ __le32 num_frame_cts_nul_flid;
+ __le32 tx_abort_failure;
+ __le32 tx_resume_failure;
+ __le32 rx_cmplt_db_overflow_cnt;
+ __le32 elp_while_rx_exch;
+ __le32 elp_while_tx_exch;
+ __le32 elp_while_tx;
+ __le32 elp_while_nvic_pending;
+ __le32 rx_excessive_frame_len;
+ __le32 burst_mismatch;
+ __le32 tbc_exch_mismatch;
+} __packed;
+
+#define NUM_OF_RATES_INDEXES 30
+struct cc33xx_acx_tx_stats {
+ __le32 tx_prepared_descs;
+ __le32 tx_cmplt;
+ __le32 tx_template_prepared;
+ __le32 tx_data_prepared;
+ __le32 tx_template_programmed;
+ __le32 tx_data_programmed;
+ __le32 tx_burst_programmed;
+ __le32 tx_starts;
+ __le32 tx_stop;
+ __le32 tx_start_templates;
+ __le32 tx_start_int_templates;
+ __le32 tx_start_fw_gen;
+ __le32 tx_start_data;
+ __le32 tx_start_null_frame;
+ __le32 tx_exch;
+ __le32 tx_retry_template;
+ __le32 tx_retry_data;
+ __le32 tx_retry_per_rate[NUM_OF_RATES_INDEXES];
+ __le32 tx_exch_pending;
+ __le32 tx_exch_expiry;
+ __le32 tx_done_template;
+ __le32 tx_done_data;
+ __le32 tx_done_int_template;
+ __le32 tx_cfe1;
+ __le32 tx_cfe2;
+ __le32 frag_called;
+ __le32 frag_mpdu_alloc_failed;
+ __le32 frag_init_called;
+ __le32 frag_in_process_called;
+ __le32 frag_tkip_called;
+ __le32 frag_key_not_found;
+ __le32 frag_need_fragmentation;
+ __le32 frag_bad_mblk_num;
+ __le32 frag_failed;
+ __le32 frag_cache_hit;
+ __le32 frag_cache_miss;
+} __packed;
+
+struct cc33xx_acx_rx_stats {
+ __le32 rx_beacon_early_term;
+ __le32 rx_out_of_mpdu_nodes;
+ __le32 rx_hdr_overflow;
+ __le32 rx_dropped_frame;
+ __le32 rx_done_stage;
+ __le32 rx_done;
+ __le32 rx_defrag;
+ __le32 rx_defrag_end;
+ __le32 rx_cmplt;
+ __le32 rx_pre_complt;
+ __le32 rx_cmplt_task;
+ __le32 rx_phy_hdr;
+ __le32 rx_timeout;
+ __le32 rx_rts_timeout;
+ __le32 rx_timeout_wa;
+ __le32 defrag_called;
+ __le32 defrag_init_called;
+ __le32 defrag_in_process_called;
+ __le32 defrag_tkip_called;
+ __le32 defrag_need_defrag;
+ __le32 defrag_decrypt_failed;
+ __le32 decrypt_key_not_found;
+ __le32 defrag_need_decrypt;
+ __le32 rx_tkip_replays;
+ __le32 rx_xfr;
+} __packed;
+
+struct cc33xx_acx_isr_stats {
+ __le32 irqs;
+} __packed;
+
+#define PWR_STAT_MAX_CONT_MISSED_BCNS_SPREAD 10
+
+struct cc33xx_acx_pwr_stats {
+ __le32 missing_bcns_cnt;
+ __le32 rcvd_bcns_cnt;
+ __le32 connection_out_of_sync;
+ __le32 cont_miss_bcns_spread[PWR_STAT_MAX_CONT_MISSED_BCNS_SPREAD];
+ __le32 rcvd_awake_bcns_cnt;
+ __le32 sleep_time_count;
+ __le32 sleep_time_avg;
+ __le32 sleep_cycle_avg;
+ __le32 sleep_percent;
+ __le32 ap_sleep_active_conf;
+ __le32 ap_sleep_user_conf;
+ __le32 ap_sleep_counter;
+} __packed;
+
+struct cc33xx_acx_rx_filter_stats {
+ __le32 beacon_filter;
+ __le32 arp_filter;
+ __le32 mc_filter;
+ __le32 dup_filter;
+ __le32 data_filter;
+ __le32 ibss_filter;
+ __le32 protection_filter;
+ __le32 accum_arp_pend_requests;
+ __le32 max_arp_queue_dep;
+} __packed;
+
+struct cc33xx_acx_rx_rate_stats {
+ __le32 rx_frames_per_rates[50];
+} __packed;
+
+#define AGGR_STATS_TX_AGG 16
+#define AGGR_STATS_RX_SIZE_LEN 16
+
+struct cc33xx_acx_aggr_stats {
+ __le32 tx_agg_rate[AGGR_STATS_TX_AGG];
+ __le32 tx_agg_len[AGGR_STATS_TX_AGG];
+ __le32 rx_size[AGGR_STATS_RX_SIZE_LEN];
+} __packed;
+
+#define PIPE_STATS_HW_FIFO 11
+
+struct cc33xx_acx_pipeline_stats {
+ __le32 hs_tx_stat_fifo_int;
+ __le32 hs_rx_stat_fifo_int;
+ __le32 enc_tx_stat_fifo_int;
+ __le32 enc_rx_stat_fifo_int;
+ __le32 rx_complete_stat_fifo_int;
+ __le32 pre_proc_swi;
+ __le32 post_proc_swi;
+ __le32 sec_frag_swi;
+ __le32 pre_to_defrag_swi;
+ __le32 defrag_to_rx_xfer_swi;
+ __le32 dec_packet_in;
+ __le32 dec_packet_in_fifo_full;
+ __le32 dec_packet_out;
+ __le16 pipeline_fifo_full[PIPE_STATS_HW_FIFO];
+ __le16 padding;
+} __packed;
+
+#define DIVERSITY_STATS_NUM_OF_ANT 2
+
+struct cc33xx_acx_diversity_stats {
+ __le32 num_of_packets_per_ant[DIVERSITY_STATS_NUM_OF_ANT];
+ __le32 total_num_of_toggles;
+} __packed;
+
+struct cc33xx_acx_thermal_stats {
+ __le16 irq_thr_low;
+ __le16 irq_thr_high;
+ __le16 tx_stop;
+ __le16 tx_resume;
+ __le16 false_irq;
+ __le16 adc_source_unexpected;
+} __packed;
+
+#define CC33XX_NUM_OF_CALIBRATIONS_ERRORS 18
+struct cc33xx_acx_calib_failure_stats {
+ __le16 fail_count[CC33XX_NUM_OF_CALIBRATIONS_ERRORS];
+ __le32 calib_count;
+} __packed;
+
+struct cc33xx_roaming_stats {
+ s32 rssi_level;
+} __packed;
+
+struct cc33xx_acx_statistics {
+ struct acx_header header;
+
+ struct cc33xx_acx_error_stats error;
+ struct cc33xx_acx_tx_stats tx;
+ struct cc33xx_acx_rx_stats rx;
+ struct cc33xx_acx_isr_stats isr;
+ struct cc33xx_acx_pwr_stats pwr;
+ struct cc33xx_acx_rx_filter_stats rx_filter;
+ struct cc33xx_acx_rx_rate_stats rx_rate;
+ struct cc33xx_acx_aggr_stats aggr_size;
+ struct cc33xx_acx_pipeline_stats pipeline;
+ struct cc33xx_acx_diversity_stats diversity;
+ struct cc33xx_acx_thermal_stats thermal;
+ struct cc33xx_acx_calib_failure_stats calib;
+ struct cc33xx_roaming_stats roaming;
+} __packed;
+
+/* ACX_PEER_CAP
+ * this struct is very similar to cc33xx_acx_ht_capabilities, with the
+ * addition of supported rates
+ */
+#define NOMINAL_PACKET_PADDING (0xC0)
+struct cc33xx_acx_peer_cap {
+ struct acx_header header;
+
+ u8 role_id;
+
+ /* rates supported by the remote peer */
+ __le32 supported_rates;
+
+ /* bitmask of capability bits supported by the peer */
+ __le32 ht_capabilites;
+ /* This the maximum A-MPDU length supported by the AP. The FW may not
+ * exceed this length when sending A-MPDUs
+ */
+ u8 ampdu_max_length;
+
+ /* This is the minimal spacing required when sending A-MPDUs to the AP*/
+ u8 ampdu_min_spacing;
+
+ /* HE capabilities */
+ u8 mac_cap_info[8];
+
+ /* Nominal packet padding value, used for determining the packet extension duration */
+ u8 nominal_packet_padding;
+
+ /* HE peer support */
+ bool has_he;
+
+ u8 dcm_max_constelation;
+
+ u8 er_upper_supported;
+
+ u8 padding;
+} __packed;
+
+struct acx_preamble_and_tx_rate {
+ struct acx_header header;
+ u16 tx_rate;
+ u8 preamble;
+ u8 role_id;
+} __packed;
+
+int cc33xx_acx_wake_up_conditions(struct cc33xx *cc, u8 wake_up_event,
+ u8 listen_interval);
+int cc33xx_acx_sleep_auth(struct cc33xx *cc, u8 sleep_auth);
+int cc33xx_acx_tx_power(struct cc33xx *cc, struct cc33xx_vif *wlvif, int power);
+int cc33xx_acx_slot(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum acx_slot_type slot_time);
+int cc33xx_acx_group_address_tbl(struct cc33xx *cc, bool enable, void *mc_list, u32 mc_list_len);
+int cc33xx_acx_beacon_filter_opt(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ bool enable_filter);
+int cc33xx_acx_beacon_filter_table(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_assoc_info_cfg(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta, u16 aid);
+int cc33xx_acx_set_preamble(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum acx_preamble_type preamble);
+int cc33xx_acx_cts_protect(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ enum acx_ctsprotect_type ctsprotect);
+int cc33xx_acx_statistics(struct cc33xx *cc, void *stats);
+int cc33xx_tx_param_cfg(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 ac,
+ u8 cw_min, u16 cw_max, u8 aifsn, u16 txop, bool acm,
+ u8 ps_scheme, u8 is_mu_edca, u8 mu_edca_aifs,
+ u8 mu_edca_ecw_min_max, u8 mu_edca_timer);
+int cc33xx_update_ap_rates(struct cc33xx *cc, u8 role_id,
+ u32 basic_rates_set, u32 supported_rates);
+int cc33xx_acx_init_mem_config(struct cc33xx *cc);
+int cc33xx_acx_init_get_fw_versions(struct cc33xx *cc);
+int cc33xx_acx_set_ht_information(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 ht_operation_mode, u32 he_oper_params,
+ u16 he_oper_nss_set);
+int cc33xx_acx_set_ba_receiver_session(struct cc33xx *cc, u8 tid_index, u16 ssn,
+ bool enable, u8 peer_hlid, u8 win_size);
+int cc33xx_acx_config_ps(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+int cc33xx_acx_get_tx_rate(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct station_info *sinfo);
+int cc33xx_acx_average_rssi(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, s8 *avg_rssi);
+int cc33xx_acx_default_rx_filter_enable(struct cc33xx *cc, bool enable,
+ enum rx_filter_action action);
+int cc33xx_acx_set_rx_filter(struct cc33xx *cc, u8 index, bool enable,
+ struct cc33xx_rx_filter *filter);
+int cc33xx_acx_clear_statistics(struct cc33xx *cc);
+int cc33xx_acx_set_peer_cap(struct cc33xx *cc,
+ struct ieee80211_sta_ht_cap *ht_cap,
+ struct ieee80211_sta_he_cap *he_cap,
+ struct cc33xx_vif *wlvif, bool allow_ht_operation,
+ u32 rate_set);
+int cc33xx_acx_trigger_fw_assert(struct cc33xx *cc);
+
+#endif /* __CC33XX_ACX_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (5 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:31 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
` (9 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
Unlike in wlcore, events are queued on linked list
(cc->event_list) and are handled outside the IRQ
context. This will be more clear when looking at main.c
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/event.c | 313 +++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/event.h | 62 +++++
2 files changed, 375 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/event.c
create mode 100644 drivers/net/wireless/ti/cc33xx/event.h
diff --git a/drivers/net/wireless/ti/cc33xx/event.c b/drivers/net/wireless/ti/cc33xx/event.c
new file mode 100644
index 000000000000..04653a727a2a
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/event.c
@@ -0,0 +1,313 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "acx.h"
+#include "event.h"
+#include "ps.h"
+#include "io.h"
+#include "scan.h"
+
+struct cc33xx_event_mailbox {
+ __le32 events_vector;
+
+ u8 number_of_scan_results;
+ u8 number_of_sched_scan_results;
+
+ __le16 channel_switch_role_id_bitmap;
+
+ s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS];
+
+ /* bitmap of removed links */
+ __le32 hlid_removed_bitmap;
+
+ /* rx ba constraint */
+ __le16 rx_ba_role_id_bitmap; /* 0xfff means any role. */
+ __le16 rx_ba_allowed_bitmap;
+
+ /* bitmap of roc completed (by role id) */
+ __le16 roc_completed_bitmap;
+
+ /* bitmap of stations (by role id) with bss loss */
+ __le16 bss_loss_bitmap;
+
+ /* bitmap of stations (by HLID) which exceeded max tx retries */
+ __le16 tx_retry_exceeded_bitmap;
+
+ /* time sync high msb*/
+ __le16 time_sync_tsf_high_msb;
+
+ /* bitmap of inactive stations (by HLID) */
+ __le16 inactive_sta_bitmap;
+
+ /* time sync high lsb*/
+ __le16 time_sync_tsf_high_lsb;
+
+ /* rx BA win size indicated by RX_BA_WIN_SIZE_CHANGE_EVENT_ID */
+ u8 rx_ba_role_id;
+ u8 rx_ba_link_id;
+ u8 rx_ba_win_size;
+ u8 padding;
+
+ /* smart config */
+ u8 sc_ssid_len;
+ u8 sc_pwd_len;
+ u8 sc_token_len;
+ u8 padding1;
+ u8 sc_ssid[32];
+ u8 sc_pwd[64];
+ u8 sc_token[32];
+
+ /* smart config sync channel */
+ u8 sc_sync_channel;
+ u8 sc_sync_band;
+
+ /* time sync low msb*/
+ __le16 time_sync_tsf_low_msb;
+
+ /* radar detect */
+ u8 radar_channel;
+ u8 radar_type;
+
+ /* time sync low lsb*/
+ __le16 time_sync_tsf_low_lsb;
+
+ u8 ble_event[260];
+
+} __packed;
+
+struct event_node {
+ struct llist_node node;
+ struct cc33xx_event_mailbox event_data;
+};
+
+void deffer_event(struct cc33xx *cc,
+ const void *event_payload, size_t event_length)
+{
+ struct event_node *event_node;
+
+ if (WARN_ON(event_length != sizeof(event_node->event_data)))
+ return;
+
+ event_node = kzalloc_obj(*event_node);
+ if (WARN_ON(!event_node))
+ return;
+
+ memcpy(&event_node->event_data,
+ event_payload, sizeof(event_node->event_data));
+
+ llist_add(&event_node->node, &cc->event_list);
+ queue_work(cc->freezable_wq, &cc->irq_deferred_work);
+}
+
+static inline struct llist_node *get_event_list(struct cc33xx *cc)
+{
+ struct llist_node *node;
+
+ node = llist_del_all(&cc->event_list);
+ if (!node)
+ return NULL;
+
+ return llist_reverse_order(node);
+}
+
+void flush_deferred_event_list(struct cc33xx *cc)
+{
+ struct event_node *event_node, *tmp;
+ struct llist_node *event_list;
+
+ event_list = get_event_list(cc);
+ llist_for_each_entry_safe(event_node, tmp, event_list, node) {
+ kfree(event_node);
+ }
+}
+
+static void cc33xx_event_sched_scan_completed(struct cc33xx *cc)
+{
+ wiphy_lock(cc->hw->wiphy);
+ if (cc->sched_vif) {
+ ieee80211_sched_scan_stopped(cc->hw);
+ cc->sched_vif = NULL;
+ }
+ wiphy_unlock(cc->hw->wiphy);
+}
+
+static void cc33xx_event_channel_switch(struct cc33xx *cc,
+ unsigned long roles_bitmap,
+ bool success)
+{
+ struct cc33xx_vif *wlvif;
+ struct ieee80211_vif *vif;
+
+ wiphy_lock(cc->hw->wiphy);
+ cc33xx_for_each_wlvif(cc, wlvif) {
+ if (wlvif->role_id == CC33XX_INVALID_ROLE_ID ||
+ !test_bit(wlvif->role_id, &roles_bitmap))
+ continue;
+
+ if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
+ &wlvif->flags))
+ continue;
+
+ vif = cc33xx_wlvif_to_vif(wlvif);
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
+ ieee80211_chswitch_done(vif, success, 0);
+ wiphy_delayed_work_cancel(cc->hw->wiphy,
+ &wlvif->channel_switch_work);
+ } else {
+ set_bit(WLVIF_FLAG_BEACON_DISABLED, &wlvif->flags);
+ ieee80211_csa_finish(vif, 0);
+ }
+ }
+ wiphy_unlock(cc->hw->wiphy);
+}
+
+static void cc33xx_disconnect_sta(struct cc33xx *cc, unsigned long sta_bitmap)
+{
+ u32 num_packets = cc->conf.host_conf.tx.max_tx_retries;
+ struct cc33xx_vif *wlvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_sta *sta;
+ const u8 *addr;
+ int h;
+
+ wiphy_lock(cc->hw->wiphy);
+ for_each_set_bit(h, &sta_bitmap, CC33XX_MAX_LINKS) {
+ bool found = false;
+ /* find the ap vif connected to this sta */
+ cc33xx_for_each_wlvif_ap(cc, wlvif) {
+ if (!test_bit(h, wlvif->ap.sta_hlid_map))
+ continue;
+ found = true;
+ break;
+ }
+ if (!found)
+ continue;
+
+ vif = cc33xx_wlvif_to_vif(wlvif);
+ addr = cc->links[h].addr;
+
+ rcu_read_lock();
+ sta = ieee80211_find_sta(vif, addr);
+ if (sta)
+ ieee80211_report_low_ack(sta, num_packets);
+
+ rcu_read_unlock();
+ }
+ wiphy_unlock(cc->hw->wiphy);
+}
+
+static void cc33xx_event_max_tx_failure(struct cc33xx *cc,
+ unsigned long sta_bitmap)
+{
+ cc33xx_disconnect_sta(cc, sta_bitmap);
+}
+
+static void cc33xx_event_roc_complete(struct cc33xx *cc)
+{
+ wiphy_lock(cc->hw->wiphy);
+ if (cc->roc_vif)
+ ieee80211_ready_on_channel(cc->hw);
+ wiphy_unlock(cc->hw->wiphy);
+}
+
+static void cc33xx_event_peer_remove_complete(struct cc33xx *cc)
+{
+ complete(&cc->peer_remove_complete);
+}
+
+static void cc33xx_event_beacon_loss(struct cc33xx *cc,
+ unsigned long roles_bitmap)
+{
+ /* We are HW_MONITOR device. On beacon loss - queue
+ * connection loss work. Cancel it on REGAINED event.
+ */
+ struct cc33xx_vif *wlvif;
+ struct ieee80211_vif *vif;
+ int delay = cc->conf.host_conf.conn.synch_fail_thold;
+
+ delay *= cc->conf.host_conf.conn.bss_lose_timeout;
+
+ wiphy_lock(cc->hw->wiphy);
+ cc33xx_for_each_wlvif_sta(cc, wlvif) {
+ if (wlvif->role_id == CC33XX_INVALID_ROLE_ID ||
+ !test_bit(wlvif->role_id, &roles_bitmap))
+ continue;
+
+ vif = cc33xx_wlvif_to_vif(wlvif);
+
+ /* don't attempt roaming in case of p2p */
+ if (wlvif->p2p) {
+ ieee80211_connection_loss(vif);
+ continue;
+ }
+
+ /* if the work is already queued, it should take place.
+ * We don't want to delay the connection loss
+ * indication any more.
+ */
+ wiphy_delayed_work_queue(cc->hw->wiphy,
+ &wlvif->connection_loss_work,
+ msecs_to_jiffies(delay));
+
+ ieee80211_cqm_beacon_loss_notify(vif, GFP_KERNEL);
+ }
+ wiphy_unlock(cc->hw->wiphy);
+}
+
+/* Caller must not hold cc->mutex lock */
+void process_deferred_events(struct cc33xx *cc)
+{
+ struct event_node *event_node, *tmp;
+ struct llist_node *event_list;
+ u32 vector;
+
+ event_list = get_event_list(cc);
+
+ llist_for_each_entry_safe(event_node, tmp, event_list, node) {
+ struct cc33xx_event_mailbox *event_data;
+
+ event_data = &event_node->event_data;
+
+ vector = le32_to_cpu(event_node->event_data.events_vector);
+
+ if (vector & SCAN_COMPLETE_EVENT_ID)
+ cc33xx_scan_completed(cc);
+
+ if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
+ cc33xx_event_sched_scan_completed(cc);
+
+ if (vector & BSS_LOSS_EVENT_ID) {
+ u16 bss_loss_bitmap = le16_to_cpu(event_data->bss_loss_bitmap);
+
+ cc33xx_event_beacon_loss(cc, bss_loss_bitmap);
+ }
+
+ if (vector & MAX_TX_FAILURE_EVENT_ID) {
+ u16 tx_retry_exceeded_bitmap =
+ le16_to_cpu(event_data->tx_retry_exceeded_bitmap);
+
+ cc33xx_event_max_tx_failure(cc, tx_retry_exceeded_bitmap);
+ }
+
+ if (vector & PERIODIC_SCAN_REPORT_EVENT_ID)
+ cc33xx_scan_sched_scan_results(cc);
+
+ if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
+ u16 channel_switch_role_id_bitmap =
+ le16_to_cpu(event_data->channel_switch_role_id_bitmap);
+
+ cc33xx_event_channel_switch(cc, channel_switch_role_id_bitmap, true);
+ }
+
+ if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
+ cc33xx_event_roc_complete(cc);
+
+ if (vector & PEER_REMOVE_COMPLETE_EVENT_ID)
+ cc33xx_event_peer_remove_complete(cc);
+
+ kfree(event_node);
+ }
+}
diff --git a/drivers/net/wireless/ti/cc33xx/event.h b/drivers/net/wireless/ti/cc33xx/event.h
new file mode 100644
index 000000000000..21cde2f96be9
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/event.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __EVENT_H__
+#define __EVENT_H__
+
+/* Mbox events
+ *
+ * The event mechanism is based on a pair of event buffers (buffers A and
+ * B) at fixed locations in the target's memory. The host processes one
+ * buffer while the other buffer continues to collect events. If the host
+ * is not processing events, an interrupt is issued to signal that a buffer
+ * is ready. Once the host is done with processing events from one buffer,
+ * it signals the target (with an ACK interrupt) that the event buffer is
+ * free.
+ */
+
+enum {
+ RSSI_SNR_TRIGGER_0_EVENT_ID = BIT(0),
+ RSSI_SNR_TRIGGER_1_EVENT_ID = BIT(1),
+ RSSI_SNR_TRIGGER_2_EVENT_ID = BIT(2),
+ RSSI_SNR_TRIGGER_3_EVENT_ID = BIT(3),
+ RSSI_SNR_TRIGGER_4_EVENT_ID = BIT(4),
+ RSSI_SNR_TRIGGER_5_EVENT_ID = BIT(5),
+ RSSI_SNR_TRIGGER_6_EVENT_ID = BIT(6),
+ RSSI_SNR_TRIGGER_7_EVENT_ID = BIT(7),
+
+ EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
+};
+
+enum {
+ SCAN_COMPLETE_EVENT_ID = BIT(8),
+ RADAR_DETECTED_EVENT_ID = BIT(9),
+ CHANNEL_SWITCH_COMPLETE_EVENT_ID = BIT(10),
+ BSS_LOSS_EVENT_ID = BIT(11),
+ MAX_TX_FAILURE_EVENT_ID = BIT(12),
+ DUMMY_PACKET_EVENT_ID = BIT(13),
+ INACTIVE_STA_EVENT_ID = BIT(14),
+ PEER_REMOVE_COMPLETE_EVENT_ID = BIT(15),
+ PERIODIC_SCAN_COMPLETE_EVENT_ID = BIT(16),
+ BA_SESSION_RX_CONSTRAINT_EVENT_ID = BIT(17),
+ REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID = BIT(18),
+ DFS_CHANNELS_CONFIG_COMPLETE_EVENT = BIT(19),
+ PERIODIC_SCAN_REPORT_EVENT_ID = BIT(20),
+ RX_BA_WIN_SIZE_CHANGE_EVENT_ID = BIT(21),
+ SMART_CONFIG_SYNC_EVENT_ID = BIT(22),
+ SMART_CONFIG_DECODE_EVENT_ID = BIT(23),
+ TIME_SYNC_EVENT_ID = BIT(24),
+ FW_LOGGER_INDICATION = BIT(25),
+};
+
+#define NUM_OF_RSSI_SNR_TRIGGERS 8
+
+struct cc33xx;
+
+void deffer_event(struct cc33xx *cc, const void *event_payload, size_t event_length);
+void process_deferred_events(struct cc33xx *cc);
+void flush_deferred_event_list(struct cc33xx *cc);
+
+#endif /* __EVENT_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (6 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:38 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 09/17] wifi: cc33xx: Add main.c Ramesh Ramalingam
` (8 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
Implements FW download for CC33xx. The FW comes in 2 parts - a 2nd stage
bootloader (cc33xx_2nd_loader.bin) and the actual FW (cc33xx_fw.bin).
Each file is requested from user space, and transferred to device
chunk by chunk. A dedicated IRQ is excepted after each stage
(Device power-on -> 2nd stage loader -> FW). This logic is implemented in
cc33xx_init_fw.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/boot.c | 341 ++++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/boot.h | 24 ++
2 files changed, 365 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/boot.c
create mode 100644 drivers/net/wireless/ti/cc33xx/boot.h
diff --git a/drivers/net/wireless/ti/cc33xx/boot.c b/drivers/net/wireless/ti/cc33xx/boot.c
new file mode 100644
index 000000000000..4ec7c315be77
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/boot.c
@@ -0,0 +1,341 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include <linux/firmware.h>
+#include <linux/vmalloc.h>
+
+#include "boot.h"
+#include "cmd.h"
+#include "debug.h"
+#include "init.h"
+#include "io.h"
+
+#define CC33XX_BOOT_TIMEOUT 2000
+
+struct hwinfo_bitmap {
+ u32 disable_5g : 1u;
+ u32 disable_6g : 1u;
+ u32 disable_ble : 1u;
+ u32 disable_ble_m0plus : 1u;
+ u32 disable_m33 : 1u;
+ u64 udi : 64u;
+ u32 pg_version : 4u;
+ u32 metal_version : 4u;
+ u32 boot_rom_version : 4u;
+ u32 m3_rom_version : 4u;
+ u32 fuse_rom_structure_version : 4u;
+ u64 mac_address : 48u;
+ u32 device_part_number : 6u;
+ u32 package_type : 4u;
+ u32 fw_rollback_protection_1 : 32u;
+ u32 fw_rollback_protection_2 : 32u;
+ u32 fw_rollback_protection_3 : 32u;
+ u32 reserved : 13u;
+} /* Aligned with boot code, must not be __packed */;
+
+union hw_info {
+ struct hwinfo_bitmap bitmap;
+ u8 bytes[sizeof(struct hwinfo_bitmap)];
+};
+
+/* Called from threaded irq context */
+void cc33xx_handle_boot_irqs(struct cc33xx *cc, u32 pending_interrupts)
+{
+ if (WARN_ON(!cc->fw_download))
+ return;
+
+ atomic_or(pending_interrupts, &cc->fw_download->pending_irqs);
+ complete(&cc->fw_download->wait_on_irq);
+}
+
+static u8 *fetch_container(struct cc33xx *cc, const char *container_name,
+ size_t *container_len)
+{
+ u8 *container_data = NULL;
+ const struct firmware *container;
+ int ret;
+
+ ret = request_firmware(&container, container_name, cc->dev);
+
+ if (ret < 0) {
+ dev_err(cc->dev, "could not get container %s: (%d)\n",
+ container_name, ret);
+ return NULL;
+ }
+
+ if (container->size % 4) {
+ dev_err(cc->dev, "container size is not word-aligned: %zu\n",
+ container->size);
+ goto out;
+ }
+
+ *container_len = container->size;
+ container_data = vmalloc(container->size);
+
+ if (!container_data)
+ goto out;
+
+ memcpy(container_data, container->data, container->size);
+
+out:
+ release_firmware(container);
+ return container_data;
+}
+
+static int cc33xx_set_power_on(struct cc33xx *cc)
+{
+ int ret;
+
+ msleep(CC33XX_PRE_POWER_ON_SLEEP);
+ ret = cc33xx_power_on(cc);
+ if (ret < 0)
+ return ret;
+
+ msleep(CC33XX_POWER_ON_SLEEP);
+ cc33xx_io_reset(cc);
+ cc33xx_io_init(cc);
+
+ return 0;
+}
+
+static int cc33xx_chip_wakeup(struct cc33xx *cc)
+{
+ int ret;
+
+ ret = cc33xx_set_power_on(cc);
+ if (ret < 0)
+ return ret;
+
+ if (!cc33xx_set_block_size(cc))
+ cc->quirks &= ~CC33XX_QUIRK_TX_BLOCKSIZE_ALIGN;
+
+ return 0;
+}
+
+static int wait_for_boot_irq(struct cc33xx *cc, u32 boot_irq_mask,
+ unsigned long timeout)
+{
+ int ret;
+ u32 pending_irqs;
+ struct cc33xx_fw_download *fw_download;
+
+ fw_download = cc->fw_download;
+
+ ret = wait_for_completion_interruptible_timeout(&fw_download->wait_on_irq,
+ msecs_to_jiffies(timeout));
+
+ /* Fetch pending IRQs while clearing them in fw_download */
+ pending_irqs = atomic_fetch_and(0, &fw_download->pending_irqs);
+ pending_irqs &= ~HINT_COMMAND_COMPLETE;
+
+ reinit_completion(&fw_download->wait_on_irq);
+
+ if (ret == 0) {
+ dev_err(cc->dev, "boot IRQ timeout\n");
+ return -1;
+ } else if (ret < 0) {
+ dev_err(cc->dev, "boot IRQ completion error %d\n", ret);
+ return -2;
+ }
+
+ if (boot_irq_mask != pending_irqs) {
+ dev_err(cc->dev, "Unexpected IRQ received @ boot: 0x%x\n",
+ pending_irqs);
+ return -3;
+ }
+
+ return 0;
+}
+
+static int download_container(struct cc33xx *cc, u8 *container, size_t len)
+{
+ int ret = 0;
+ u8 *current_transfer;
+ size_t current_transfer_size;
+ u8 *const container_end = container + len;
+ size_t max_transfer_size = cc->fw_download->max_transfer_size;
+ bool is_last_transfer;
+
+ current_transfer = container;
+
+ while (current_transfer < container_end) {
+ current_transfer_size = container_end - current_transfer;
+ current_transfer_size =
+ min(current_transfer_size, max_transfer_size);
+
+ is_last_transfer = (current_transfer + current_transfer_size >= container_end);
+
+ ret = cc33xx_cmd_download_container_chunk(cc,
+ current_transfer,
+ current_transfer_size,
+ is_last_transfer);
+
+ current_transfer += current_transfer_size;
+
+ if (ret < 0) {
+ dev_err(cc->dev, "Chunk transfer failed\n");
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static int container_download_and_wait(struct cc33xx *cc,
+ const char *container_name,
+ const u32 irq_wait_mask)
+{
+ int ret = -1;
+ u8 *container_data;
+ size_t container_len;
+
+ container_data = fetch_container(cc, container_name, &container_len);
+ if (!container_data)
+ return ret;
+
+ ret = download_container(cc, container_data, container_len);
+ if (ret < 0) {
+ dev_err(cc->dev, "Transfer error while downloading %s\n",
+ container_name);
+ goto out;
+ }
+
+ ret = wait_for_boot_irq(cc, irq_wait_mask, CC33XX_BOOT_TIMEOUT);
+
+ if (ret < 0) {
+ dev_err(cc->dev, "%s boot signal timeout\n", container_name);
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ vfree(container_data);
+ return ret;
+}
+
+static int fw_download_alloc(struct cc33xx *cc)
+{
+ if (WARN_ON(cc->fw_download))
+ return -EFAULT;
+
+ cc->fw_download = kzalloc_obj(*cc->fw_download);
+ if (!cc->fw_download)
+ return -ENOMEM;
+
+ init_completion(&cc->fw_download->wait_on_irq);
+
+ return 0;
+}
+
+static void fw_download_free(struct cc33xx *cc)
+{
+ if (WARN_ON(!cc->fw_download))
+ return;
+
+ kfree(cc->fw_download);
+ cc->fw_download = NULL;
+}
+
+static int get_device_info(struct cc33xx *cc)
+{
+ int ret;
+ union hw_info hw_info;
+ u64 mac_address;
+
+ ret = cc33xx_cmd_get_device_info(cc, hw_info.bytes, sizeof(hw_info.bytes));
+ if (ret < 0)
+ return ret;
+
+ cc->fw_download->max_transfer_size = 640;
+
+ mac_address = hw_info.bitmap.mac_address;
+
+ cc->fuse_rom_structure_version = hw_info.bitmap.fuse_rom_structure_version;
+ cc->pg_version = hw_info.bitmap.pg_version;
+ cc->device_part_number = hw_info.bitmap.device_part_number;
+ cc->disable_5g = hw_info.bitmap.disable_5g;
+ cc->disable_6g = hw_info.bitmap.disable_6g;
+
+ cc->efuse_mac_address[5] = (u8)(mac_address);
+ cc->efuse_mac_address[4] = (u8)(mac_address >> 8);
+ cc->efuse_mac_address[3] = (u8)(mac_address >> 16);
+ cc->efuse_mac_address[2] = (u8)(mac_address >> 24);
+ cc->efuse_mac_address[1] = (u8)(mac_address >> 32);
+ cc->efuse_mac_address[0] = (u8)(mac_address >> 40);
+
+ return 0;
+}
+
+int cc33xx_init_fw(struct cc33xx *cc)
+{
+ int ret;
+
+ cc->max_cmd_size = CC33XX_CMD_MAX_SIZE;
+
+ ret = fw_download_alloc(cc);
+ if (ret < 0)
+ return ret;
+
+ reinit_completion(&cc->fw_download->wait_on_irq);
+
+ ret = cc33xx_chip_wakeup(cc);
+ if (ret < 0)
+ goto power_off;
+
+ cc33xx_enable_interrupts(cc);
+
+ ret = wait_for_boot_irq(cc, HINT_ROM_LOADER_INIT_COMPLETE,
+ CC33XX_BOOT_TIMEOUT);
+ if (ret < 0)
+ goto disable_irq;
+
+ ret = get_device_info(cc);
+ if (ret < 0)
+ goto disable_irq;
+
+ ret = container_download_and_wait(cc, SECOND_LOADER_NAME,
+ HINT_SECOND_LOADER_INIT_COMPLETE);
+ if (ret < 0)
+ goto disable_irq;
+
+ ret = container_download_and_wait(cc, FW_NAME,
+ HINT_FW_WAKEUP_COMPLETE);
+ if (ret < 0)
+ goto disable_irq;
+
+ ret = cc33xx_download_ini_params_and_wait(cc);
+
+ if (ret < 0)
+ goto disable_irq;
+
+ ret = wait_for_boot_irq(cc, HINT_FW_INIT_COMPLETE, CC33XX_BOOT_TIMEOUT);
+
+ if (ret < 0)
+ goto disable_irq;
+
+ ret = cc33xx_hw_init(cc);
+ if (ret < 0)
+ goto disable_irq;
+
+ /* Now we know if 11a is supported (info from the INI File), so disable
+ * 11a channels if not supported
+ */
+ cc->enable_11a = cc->conf.core.enable_5ghz;
+
+ cc->state = CC33XX_STATE_ON;
+ ret = 0;
+ goto out;
+
+disable_irq:
+ cc33xx_disable_interrupts_nosync(cc);
+
+power_off:
+ cc33xx_power_off(cc);
+
+out:
+ fw_download_free(cc);
+ return ret;
+}
diff --git a/drivers/net/wireless/ti/cc33xx/boot.h b/drivers/net/wireless/ti/cc33xx/boot.h
new file mode 100644
index 000000000000..ca37f8b948bd
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/boot.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __BOOT_H__
+#define __BOOT_H__
+
+#include "cc33xx.h"
+
+int cc33xx_init_fw(struct cc33xx *cc);
+
+void cc33xx_handle_boot_irqs(struct cc33xx *cc, u32 pending_interrupts);
+
+#define SECOND_LOADER_NAME "ti-connectivity/cc33xx_2nd_loader.bin"
+#define FW_NAME "ti-connectivity/cc33xx_fw.bin"
+
+struct cc33xx_fw_download {
+ atomic_t pending_irqs;
+ struct completion wait_on_irq;
+ size_t max_transfer_size;
+};
+
+#endif /* __BOOT_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 09/17] wifi: cc33xx: Add main.c
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (7 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
` (7 subsequent siblings)
16 siblings, 0 replies; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
General code and structures.
Notably:
cc33xx_irq - Handles IRQs received from the device.
process_core_status - Core status is a new concept in CC33xx.
it's a structure that is appended to each transfer from the device and
contains its most up-to-date status report (IRQs, buffers, etc.).
See struct core_status for details.
process_event_and_cmd_result - Responses to driver commands and
FW events both arrive asynchronously. Therefore, driver cannot know what
he read from HW until inspecting the payload. This code reads and
dispatches the data accordingly.
cc33xx_recovery_work - Driver supports basic recovery on FW crash and
other illegal conditions. This implements the recovery flow
(Remove all vifs, turn device off and on, download FW,
let ieee80211_restart_hw do the rest).
irq_deferred_work - Does irq-related work. This is mostly in response
to HW's Tx/Rx IRQs.
cc33xx_nvs_cb - Callback for the NVS FW request API. Similar to wlcore,
this is where the init of the HW is performed.
cc33xx_load_ini_bin_file - Loads a configuration file from user-space
via the request FW API. The structure is described in a separate patch.
cc33xx_op_X - MAC80211 operation handlers.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/main.c | 4820 +++++++++++++++++++++++++
1 file changed, 4820 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/main.c
diff --git a/drivers/net/wireless/ti/cc33xx/main.c b/drivers/net/wireless/ti/cc33xx/main.c
new file mode 100644
index 000000000000..b34bed565a46
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/main.c
@@ -0,0 +1,4820 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/firmware.h>
+#include <linux/irq.h>
+#include <linux/pm_wakeirq.h>
+
+#include "acx.h"
+#include "boot.h"
+#include "io.h"
+#include "tx.h"
+#include "ps.h"
+#include "init.h"
+#include "testmode.h"
+#include "scan.h"
+#include "event.h"
+
+#define CC33XX_FW_RX_PACKET_RAM (9 * 1024)
+
+static int no_recovery = -1;
+
+u32 cc33xx_debug_level = DEBUG_NO_DATAPATH;
+
+static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+
+/* HT cap appropriate for wide channels in 2Ghz */
+static struct ieee80211_sta_ht_cap cc33xx_siso40_ht_cap_2ghz = {
+ .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
+ IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_DSSSCCK40 |
+ IEEE80211_HT_CAP_GRN_FLD,
+ .ht_supported = true,
+ .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
+ .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(150),
+ .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
+ },
+};
+
+/* HT cap appropriate for wide channels in 5Ghz */
+static struct ieee80211_sta_ht_cap cc33xx_siso40_ht_cap_5ghz = {
+ .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
+ IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
+ IEEE80211_HT_CAP_GRN_FLD,
+ .ht_supported = true,
+ .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
+ .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(150),
+ .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
+ },
+};
+
+/* HT cap appropriate for SISO 20 */
+static struct ieee80211_sta_ht_cap cc33xx_siso20_ht_cap = {
+ .cap = IEEE80211_HT_CAP_SGI_20 |
+ IEEE80211_HT_CAP_MAX_AMSDU,
+ .ht_supported = true,
+ .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
+ .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(72),
+ .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
+ },
+};
+
+static const struct ieee80211_iface_limit cc33xx_iface_limits[] = {
+ {
+ .max = 2,
+ .types = BIT(NL80211_IFTYPE_STATION)
+ },
+ {
+ .max = 1,
+ .types = BIT(NL80211_IFTYPE_AP)
+#ifdef CONFIG_MAC80211_MESH
+ | BIT(NL80211_IFTYPE_MESH_POINT)
+#endif
+ },
+};
+
+static u16 cc33xx_wiphy_interface_modes(void)
+{
+ return BIT(NL80211_IFTYPE_STATION) |
+#ifdef CONFIG_MAC80211_MESH
+ BIT(NL80211_IFTYPE_MESH_POINT) |
+#endif
+ BIT(NL80211_IFTYPE_AP);
+}
+
+static inline void cc33xx_set_ht_cap(struct cc33xx *cc, enum nl80211_band band,
+ struct ieee80211_sta_ht_cap *ht_cap)
+{
+ memcpy(&cc->ht_cap[band], ht_cap, sizeof(*ht_cap));
+}
+
+static const struct ieee80211_iface_combination
+cc33xx_iface_combinations[] = {
+ {
+ .max_interfaces = 3,
+ .limits = cc33xx_iface_limits,
+ .n_limits = ARRAY_SIZE(cc33xx_iface_limits),
+ .num_different_channels = 2,
+ }
+};
+
+static const u8 cc33xx_rate_to_idx_2ghz[] = {
+ [0] = CONF_HW_RXTX_RATE_UNSUPPORTED,
+ [CONF_HW_RATE_INDEX_1MBPS] = 0, /* RATE_INDEX_1MBPS */
+ [CONF_HW_RATE_INDEX_2MBPS] = 1, /* RATE_INDEX_2MBPS */
+ [CONF_HW_RATE_INDEX_5_5MBPS] = 2, /* RATE_INDEX_5_5MBPS */
+ [CONF_HW_RATE_INDEX_11MBPS] = 3, /* RATE_INDEX_11MBPS */
+ [CONF_HW_RATE_INDEX_6MBPS] = 4, /* RATE_INDEX_6MBPS */
+ [CONF_HW_RATE_INDEX_9MBPS] = 5, /* RATE_INDEX_9MBPS */
+ [CONF_HW_RATE_INDEX_12MBPS] = 6, /* RATE_INDEX_12MBPS */
+ [CONF_HW_RATE_INDEX_18MBPS] = 7, /* RATE_INDEX_18MBPS */
+ [CONF_HW_RATE_INDEX_24MBPS] = 8, /* RATE_INDEX_24MBPS */
+ [CONF_HW_RATE_INDEX_36MBPS] = 9, /* RATE_INDEX_36MBPS */
+ [CONF_HW_RATE_INDEX_48MBPS] = 10, /* RATE_INDEX_48MBPS */
+ [CONF_HW_RATE_INDEX_54MBPS] = 11, /* RATE_INDEX_54MBPS */
+ [CONF_HW_RATE_INDEX_MCS0] = 0, /* RATE_INDEX_MCS0 */
+ [CONF_HW_RATE_INDEX_MCS1] = 1, /* RATE_INDEX_MCS1 */
+ [CONF_HW_RATE_INDEX_MCS2] = 2, /* RATE_INDEX_MCS2 */
+ [CONF_HW_RATE_INDEX_MCS3] = 3, /* RATE_INDEX_MCS3 */
+ [CONF_HW_RATE_INDEX_MCS4] = 4, /* RATE_INDEX_MCS4 */
+ [CONF_HW_RATE_INDEX_MCS5] = 5, /* RATE_INDEX_MCS5 */
+ [CONF_HW_RATE_INDEX_MCS6] = 6, /* RATE_INDEX_MCS6 */
+ [CONF_HW_RATE_INDEX_MCS7] = 7 /* RATE_INDEX_MCS7 */
+};
+
+static const u8 cc33xx_rate_to_idx_5ghz[] = {
+ [0] = CONF_HW_RXTX_RATE_UNSUPPORTED,
+ [CONF_HW_RATE_INDEX_1MBPS] = CONF_HW_RXTX_RATE_UNSUPPORTED, /* RATE_INDEX_1MBPS */
+ [CONF_HW_RATE_INDEX_2MBPS] = CONF_HW_RXTX_RATE_UNSUPPORTED, /* RATE_INDEX_2MBPS */
+ [CONF_HW_RATE_INDEX_5_5MBPS] = CONF_HW_RXTX_RATE_UNSUPPORTED, /* RATE_INDEX_5_5MBPS */
+ [CONF_HW_RATE_INDEX_11MBPS] = CONF_HW_RXTX_RATE_UNSUPPORTED, /* RATE_INDEX_11MBPS */
+ [CONF_HW_RATE_INDEX_6MBPS] = 0, /* RATE_INDEX_6MBPS */
+ [CONF_HW_RATE_INDEX_9MBPS] = 1, /* RATE_INDEX_9MBPS */
+ [CONF_HW_RATE_INDEX_12MBPS] = 2, /* RATE_INDEX_12MBPS */
+ [CONF_HW_RATE_INDEX_18MBPS] = 3, /* RATE_INDEX_18MBPS */
+ [CONF_HW_RATE_INDEX_24MBPS] = 4, /* RATE_INDEX_24MBPS */
+ [CONF_HW_RATE_INDEX_36MBPS] = 5, /* RATE_INDEX_36MBPS */
+ [CONF_HW_RATE_INDEX_48MBPS] = 6, /* RATE_INDEX_48MBPS */
+ [CONF_HW_RATE_INDEX_54MBPS] = 7, /* RATE_INDEX_54MBPS */
+ [CONF_HW_RATE_INDEX_MCS0] = 0, /* RATE_INDEX_MCS0 */
+ [CONF_HW_RATE_INDEX_MCS1] = 1, /* RATE_INDEX_MCS1 */
+ [CONF_HW_RATE_INDEX_MCS2] = 2, /* RATE_INDEX_MCS2 */
+ [CONF_HW_RATE_INDEX_MCS3] = 3, /* RATE_INDEX_MCS3 */
+ [CONF_HW_RATE_INDEX_MCS4] = 4, /* RATE_INDEX_MCS4 */
+ [CONF_HW_RATE_INDEX_MCS5] = 5, /* RATE_INDEX_MCS5 */
+ [CONF_HW_RATE_INDEX_MCS6] = 6, /* RATE_INDEX_MCS6 */
+ [CONF_HW_RATE_INDEX_MCS7] = 7 /* RATE_INDEX_MCS7 */
+};
+
+static const u8 *cc33xx_band_rate_to_idx[] = {
+ [NL80211_BAND_2GHZ] = cc33xx_rate_to_idx_2ghz,
+ [NL80211_BAND_5GHZ] = cc33xx_rate_to_idx_5ghz
+};
+
+/* can't be const, cfg80211 writes to this */
+static struct ieee80211_rate cc33xx_rates[] = {
+ { .bitrate = 10,
+ .hw_value = CONF_HW_BIT_RATE_1MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
+ { .bitrate = 20,
+ .hw_value = CONF_HW_BIT_RATE_2MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
+ .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+ { .bitrate = 55,
+ .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
+ .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+ { .bitrate = 110,
+ .hw_value = CONF_HW_BIT_RATE_11MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
+ .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+ { .bitrate = 60,
+ .hw_value = CONF_HW_BIT_RATE_6MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
+ { .bitrate = 90,
+ .hw_value = CONF_HW_BIT_RATE_9MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
+ { .bitrate = 120,
+ .hw_value = CONF_HW_BIT_RATE_12MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
+ { .bitrate = 180,
+ .hw_value = CONF_HW_BIT_RATE_18MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
+ { .bitrate = 240,
+ .hw_value = CONF_HW_BIT_RATE_24MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
+ { .bitrate = 360,
+ .hw_value = CONF_HW_BIT_RATE_36MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
+ { .bitrate = 480,
+ .hw_value = CONF_HW_BIT_RATE_48MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
+ { .bitrate = 540,
+ .hw_value = CONF_HW_BIT_RATE_54MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
+};
+
+/* can't be const, cfg80211 writes to this */
+static struct ieee80211_channel cc33xx_channels[] = {
+ { .hw_value = 1, .center_freq = 2412, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 2, .center_freq = 2417, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 3, .center_freq = 2422, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 4, .center_freq = 2427, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 5, .center_freq = 2432, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 6, .center_freq = 2437, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 7, .center_freq = 2442, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 8, .center_freq = 2447, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 9, .center_freq = 2452, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 10, .center_freq = 2457, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 11, .center_freq = 2462, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 12, .center_freq = 2467, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 13, .center_freq = 2472, .max_power = CC33XX_MAX_TXPWR },
+};
+
+static const struct ieee80211_sband_iftype_data iftype_data_2ghz[] = {{
+ .types_mask = BIT(NL80211_IFTYPE_STATION),
+ .he_cap = {
+ .has_he = true,
+ .he_cap_elem = {
+ .mac_cap_info[0] =
+ IEEE80211_HE_MAC_CAP0_HTC_HE |
+ IEEE80211_HE_MAC_CAP0_TWT_REQ,
+ .mac_cap_info[1] =
+ IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
+ IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
+ .mac_cap_info[2] =
+ IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP |
+ IEEE80211_HE_MAC_CAP2_ALL_ACK |
+ IEEE80211_HE_MAC_CAP2_TRS |
+ IEEE80211_HE_MAC_CAP2_BSR |
+ IEEE80211_HE_MAC_CAP2_ACK_EN,
+ .mac_cap_info[3] =
+ IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
+ IEEE80211_HE_MAC_CAP3_RX_CTRL_FRAME_TO_MULTIBSS,
+ .mac_cap_info[4] =
+ IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU |
+ IEEE80211_HE_MAC_CAP4_NDP_FB_REP |
+ IEEE80211_HE_MAC_CAP4_MULTI_TID_AGG_TX_QOS_B39,
+ .mac_cap_info[5] =
+ IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX,
+ .phy_cap_info[0] = 0,
+ .phy_cap_info[1] =
+ IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
+ IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US,
+ .phy_cap_info[2] =
+ IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US,
+ .phy_cap_info[3] =
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_NO_DCM |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1,
+ .phy_cap_info[4] =
+ IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
+ IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4,
+ .phy_cap_info[5] =
+ IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
+ IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK,
+ .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_TRIG_CQI_FB |
+ IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE,
+ .phy_cap_info[7] =
+ IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI,
+ .phy_cap_info[8] =
+ IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
+ IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
+ IEEE80211_HE_PHY_CAP8_HE_ER_SU_1XLTF_AND_08_US_GI,
+ .phy_cap_info[9] =
+ IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
+ 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 |
+ IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
+ },
+ /* Set default Tx/Rx HE MCS NSS Support field.
+ * Indicate support for up to 2 spatial streams and all
+ * MCS, without any special cases
+ */
+ .he_mcs_nss_supp = {
+ .rx_mcs_80 = cpu_to_le16(0xfffc),
+ .tx_mcs_80 = cpu_to_le16(0xfffc),
+ .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),
+ },
+ /* Set default PPE thresholds, with PPET16 set to 0,
+ * PPET8 set to 7
+ */
+ .ppe_thres = {0xff, 0xff, 0xff, 0xff},
+ },
+}};
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_supported_band cc33xx_band_2ghz = {
+ .channels = cc33xx_channels,
+ .n_channels = ARRAY_SIZE(cc33xx_channels),
+ .bitrates = cc33xx_rates,
+ .n_bitrates = ARRAY_SIZE(cc33xx_rates),
+};
+
+/* 5 GHz data rates for cc33xx */
+static struct ieee80211_rate cc33xx_rates_5ghz[] = {
+ { .bitrate = 60,
+ .hw_value = CONF_HW_BIT_RATE_6MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
+ { .bitrate = 90,
+ .hw_value = CONF_HW_BIT_RATE_9MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
+ { .bitrate = 120,
+ .hw_value = CONF_HW_BIT_RATE_12MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
+ { .bitrate = 180,
+ .hw_value = CONF_HW_BIT_RATE_18MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
+ { .bitrate = 240,
+ .hw_value = CONF_HW_BIT_RATE_24MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
+ { .bitrate = 360,
+ .hw_value = CONF_HW_BIT_RATE_36MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
+ { .bitrate = 480,
+ .hw_value = CONF_HW_BIT_RATE_48MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
+ { .bitrate = 540,
+ .hw_value = CONF_HW_BIT_RATE_54MBPS,
+ .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
+};
+
+/* 5 GHz band channels for cc33xx */
+static struct ieee80211_channel cc33xx_channels_5ghz[] = {
+ { .hw_value = 36, .center_freq = 5180, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 40, .center_freq = 5200, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 44, .center_freq = 5220, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 48, .center_freq = 5240, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 52, .center_freq = 5260, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 56, .center_freq = 5280, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 60, .center_freq = 5300, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 64, .center_freq = 5320, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 100, .center_freq = 5500, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 104, .center_freq = 5520, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 108, .center_freq = 5540, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 112, .center_freq = 5560, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 116, .center_freq = 5580, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 120, .center_freq = 5600, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 124, .center_freq = 5620, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 128, .center_freq = 5640, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 132, .center_freq = 5660, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 136, .center_freq = 5680, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 140, .center_freq = 5700, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 149, .center_freq = 5745, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 153, .center_freq = 5765, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 157, .center_freq = 5785, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 161, .center_freq = 5805, .max_power = CC33XX_MAX_TXPWR },
+ { .hw_value = 165, .center_freq = 5825, .max_power = CC33XX_MAX_TXPWR },
+};
+
+static const struct ieee80211_sband_iftype_data iftype_data_5ghz[] = {{
+ .types_mask = BIT(NL80211_IFTYPE_STATION),
+ .he_cap = {
+ .has_he = true,
+ .he_cap_elem = {
+ .mac_cap_info[0] =
+ IEEE80211_HE_MAC_CAP0_HTC_HE |
+ IEEE80211_HE_MAC_CAP0_TWT_REQ,
+ .mac_cap_info[1] =
+ IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
+ IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
+ .mac_cap_info[2] =
+ IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP |
+ IEEE80211_HE_MAC_CAP2_ALL_ACK |
+ IEEE80211_HE_MAC_CAP2_TRS |
+ IEEE80211_HE_MAC_CAP2_BSR |
+ IEEE80211_HE_MAC_CAP2_ACK_EN,
+ .mac_cap_info[3] =
+ IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
+ IEEE80211_HE_MAC_CAP3_RX_CTRL_FRAME_TO_MULTIBSS,
+ .mac_cap_info[4] =
+ IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU |
+ IEEE80211_HE_MAC_CAP4_NDP_FB_REP |
+ IEEE80211_HE_MAC_CAP4_MULTI_TID_AGG_TX_QOS_B39,
+ .mac_cap_info[5] =
+ IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX,
+ .phy_cap_info[0] = 0,
+ .phy_cap_info[1] =
+ IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
+ IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US,
+ .phy_cap_info[2] =
+ IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US,
+ .phy_cap_info[3] =
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_NO_DCM |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_16_QAM |
+ IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1,
+ .phy_cap_info[4] =
+ IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
+ IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4,
+ .phy_cap_info[5] =
+ IEEE80211_HE_PHY_CAP5_NG16_SU_FEEDBACK |
+ IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK,
+ .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_TRIG_CQI_FB |
+ IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE,
+ .phy_cap_info[7] =
+ IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI,
+ .phy_cap_info[8] =
+ IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
+ IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
+ IEEE80211_HE_PHY_CAP8_HE_ER_SU_1XLTF_AND_08_US_GI,
+ .phy_cap_info[9] =
+ IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
+ 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 |
+ IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US,
+ },
+ /* Set default Tx/Rx HE MCS NSS Support field.
+ * Indicate support for up to 2 spatial streams and all
+ * MCS, without any special cases
+ */
+ .he_mcs_nss_supp = {
+ .rx_mcs_80 = cpu_to_le16(0xfffc),
+ .tx_mcs_80 = cpu_to_le16(0xfffc),
+ .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),
+ },
+ /* Set default PPE thresholds, with PPET16 set to 0,
+ * PPET8 set to 7
+ */
+ .ppe_thres = {0xff, 0xff, 0xff, 0xff},
+ },
+}};
+
+static struct ieee80211_supported_band cc33xx_band_5ghz = {
+ .channels = cc33xx_channels_5ghz,
+ .n_channels = ARRAY_SIZE(cc33xx_channels_5ghz),
+ .bitrates = cc33xx_rates_5ghz,
+ .n_bitrates = ARRAY_SIZE(cc33xx_rates_5ghz),
+ .vht_cap = {
+ .vht_supported = true,
+ .cap = (IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | (1 <<
+ IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT)),
+ .vht_mcs = {
+ .rx_mcs_map = cpu_to_le16(0xfffc),
+ .rx_highest = cpu_to_le16(7),
+ .tx_mcs_map = cpu_to_le16(0xfffc),
+ .tx_highest = cpu_to_le16(7),
+ },
+ },
+};
+
+static void __cc33xx_op_remove_interface(struct cc33xx *cc,
+ struct ieee80211_vif *vif);
+static void cc33xx_turn_off(struct cc33xx *cc);
+static void cc33xx_free_ap_keys(struct cc33xx_vif *wlvif);
+static int process_core_status(struct cc33xx *cc,
+ struct core_status *core_status);
+static int cc33xx_setup(struct cc33xx *cc);
+
+static int cc33xx_set_authorized(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret;
+
+ if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
+ return -EINVAL;
+
+ if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ return 0;
+
+ if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
+ return 0;
+
+ ret = cc33xx_cmd_set_peer_state(cc, wlvif->sta.hlid);
+ if (ret < 0)
+ return ret;
+
+ dev_info(cc->dev, "Association complete.\n");
+ return 0;
+}
+
+static void cc33xx_adjust_conf(struct cc33xx *cc)
+{
+ if (no_recovery != -1)
+ cc->conf.core.no_recovery = (u8)no_recovery;
+}
+
+void cc33xx_flush_deferred_work(struct cc33xx *cc)
+{
+ struct sk_buff *skb;
+
+ /* Pass all received frames to the network stack */
+ while ((skb = skb_dequeue(&cc->deferred_rx_queue))) {
+ cc33xx_debug(cc->dev, DEBUG_RX, "%s: rx skb 0x%p\n", __func__, skb);
+ ieee80211_rx_ni(cc->hw, skb);
+ }
+
+ /* Return sent skbs to the network stack */
+ while ((skb = skb_dequeue(&cc->deferred_tx_queue)))
+ ieee80211_tx_status_ni(cc->hw, skb);
+}
+
+static void cc33xx_netstack_work(struct work_struct *work)
+{
+ struct cc33xx *cc = container_of(work, struct cc33xx, netstack_work);
+
+ do {
+ cc33xx_flush_deferred_work(cc);
+ } while (skb_queue_len(&cc->deferred_rx_queue));
+}
+
+static int cc33xx_irq_work(struct cc33xx *cc)
+{
+ int ret = 0;
+ struct core_status *core_status_ptr;
+ u8 *rx_buf_ptr;
+ u16 rx_buf_len;
+ size_t read_data_len;
+ const size_t maximum_rx_packet_size = CC33XX_FW_RX_PACKET_RAM;
+ size_t rx_byte_count;
+ struct nab_rx_header *nab_rx_header;
+
+ process_deferred_events(cc);
+
+ guard(mutex)(&cc->mutex);
+
+ claim_core_status_lock(cc);
+
+ rx_byte_count = le32_get_bits(cc->core_status->rx_status, RX_BYTE_COUNT_MASK);
+ if (rx_byte_count != 0) {
+ const int read_headers_len = sizeof(struct core_status)
+ + sizeof(struct nab_rx_header);
+
+ /* Read aggressively as more data might be coming in */
+ rx_byte_count *= 2;
+
+ read_data_len = rx_byte_count + read_headers_len;
+
+ if (cc->max_transaction_len) { /* Used in SPI interface */
+ const int spi_alignment = sizeof(u32) - 1;
+
+ read_data_len = __ALIGN_MASK(read_data_len,
+ spi_alignment);
+ read_data_len = min(read_data_len,
+ cc->max_transaction_len);
+ } else { /* SDIO */
+ const int sdio_alignment = CC33XX_BUS_BLOCK_SIZE - 1;
+
+ read_data_len = __ALIGN_MASK(read_data_len,
+ sdio_alignment);
+ read_data_len = min(read_data_len,
+ maximum_rx_packet_size);
+ }
+
+ ret = cc33xx_raw_read(cc, CC33XX_NAB_DATA_ADDR, cc->aggr_buf,
+ read_data_len, true);
+ if (ret < 0) {
+ release_core_status_lock(cc);
+ return ret;
+ }
+
+ core_status_ptr = (struct core_status *)((u8 *)cc->aggr_buf +
+ read_data_len - sizeof(struct core_status));
+
+ memcpy(cc->core_status,
+ core_status_ptr, sizeof(struct core_status));
+
+ process_core_status(cc, cc->core_status);
+
+ release_core_status_lock(cc);
+
+ nab_rx_header = (struct nab_rx_header *)cc->aggr_buf;
+ rx_buf_len = le16_to_cpu(nab_rx_header->len) - 8;
+ if (rx_buf_len != 0) {
+ rx_buf_ptr = (u8 *)cc->aggr_buf + sizeof(struct nab_rx_header);
+ cc33xx_rx(cc, rx_buf_ptr, rx_buf_len);
+ } else {
+ dev_err(cc->dev, "Rx buffer length is 0\n");
+ cc33xx_queue_recovery_work(cc);
+ }
+ } else {
+ release_core_status_lock(cc);
+ }
+
+ cc33xx_tx_immediate_complete(cc);
+
+ return ret;
+}
+
+static int read_core_status(struct cc33xx *cc, struct core_status *core_status)
+{
+ return cc33xx_raw_read(cc, CC33XX_NAB_STATUS_ADDR, core_status,
+ sizeof(*core_status), false);
+}
+
+#define CC33XX_CTRL_TYPE_BITS 4
+static int get_type(struct control_info_descriptor *control_info_descriptor)
+{
+ u16 type_mask = GENMASK(CC33XX_CTRL_TYPE_BITS - 1, 0);
+
+ return le16_get_bits(control_info_descriptor->type_and_length, type_mask);
+}
+
+static unsigned int get_length(struct control_info_descriptor *control_info_descriptor)
+{
+ u16 length_mask = GENMASK(15, CC33XX_CTRL_TYPE_BITS);
+
+ return le16_get_bits(control_info_descriptor->type_and_length, length_mask);
+}
+
+static int parse_control_message(struct cc33xx *cc,
+ const u8 *buffer, size_t buffer_length)
+{
+ const u8 *const end_of_payload = buffer + buffer_length;
+ const u8 *const start_of_payload = buffer;
+ struct control_info_descriptor *control_info_descriptor;
+ const u8 *event_data, *cmd_result_data;
+ unsigned int ctrl_info_type, ctrl_info_length;
+
+ while (buffer < end_of_payload) {
+ control_info_descriptor =
+ (struct control_info_descriptor *)buffer;
+
+ ctrl_info_type = get_type(control_info_descriptor);
+ ctrl_info_length = get_length(control_info_descriptor);
+
+ cc33xx_debug(cc->dev, DEBUG_CMD, "Processing message type %d, len %d\n",
+ ctrl_info_type, ctrl_info_length);
+
+ switch (ctrl_info_type) {
+ case CTRL_MSG_EVENT:
+ event_data = buffer + sizeof(*control_info_descriptor);
+
+ deffer_event(cc, event_data, ctrl_info_length);
+ break;
+
+ case CTRL_MSG_COMMND_COMPLETE:
+ cmd_result_data = buffer;
+ cmd_result_data += sizeof(*control_info_descriptor);
+
+ if (ctrl_info_length > sizeof(cc->command_result)) {
+ print_hex_dump(KERN_DEBUG, "message dump:",
+ DUMP_PREFIX_OFFSET, 16, 1,
+ cmd_result_data,
+ ctrl_info_length, false);
+
+ WARN(1, "Error device response exceeds result buffer size\n");
+ return -EIO;
+ }
+
+ memcpy(cc->command_result,
+ cmd_result_data, ctrl_info_length);
+
+ cc->result_length = ctrl_info_length;
+
+ complete(&cc->command_complete);
+ break;
+
+ default:
+ print_hex_dump(KERN_DEBUG, "message dump:",
+ DUMP_PREFIX_OFFSET, 16, 1,
+ start_of_payload, buffer_length, false);
+
+ WARN(1, "Error processing device message @ offset %zu\n",
+ (size_t)(buffer - start_of_payload));
+
+ return -EIO;
+ }
+
+ buffer += sizeof(*control_info_descriptor);
+ buffer += ctrl_info_length;
+ }
+
+ return 0;
+}
+
+static int read_control_message(struct cc33xx *cc, u8 *read_buffer,
+ size_t buffer_size)
+{
+ int ret;
+ size_t device_message_size;
+ struct nab_header *nab_header;
+
+ ret = cc33xx_raw_read(cc, CC33XX_NAB_CONTROL_ADDR, read_buffer,
+ buffer_size, false);
+
+ if (ret < 0) {
+ cc33xx_debug(cc->dev, DEBUG_CMD,
+ "control read Error response 0x%x\n", ret);
+ return ret;
+ }
+
+ nab_header = (struct nab_header *)read_buffer;
+
+ if (le32_to_cpu(nab_header->sync_pattern) != CC33XX_DEVICE_SYNC_PATTERN) {
+ dev_err(cc->dev, "Wrong device sync pattern: 0x%x\n",
+ nab_header->sync_pattern);
+ return -EIO;
+ }
+
+ device_message_size = sizeof(*nab_header) + CC33XX_NAB_EXTRA_BYTES
+ + le16_to_cpu(nab_header->len);
+
+ if (device_message_size > buffer_size) {
+ dev_err(cc->dev, "Invalid NAB length field: %x\n", nab_header->len);
+ return -EIO;
+ }
+
+ return le16_to_cpu(nab_header->len);
+}
+
+static int process_event_and_cmd_result(struct cc33xx *cc,
+ struct core_status *core_status)
+{
+ int ret;
+ u8 *message;
+ const size_t buffer_size = CC33XX_CMD_MAX_SIZE;
+ size_t message_length;
+ struct core_status *new_core_status;
+ __le32 previous_hint;
+
+ u8 *read_buffer __free(kfree) = NULL;
+
+ read_buffer = kmalloc(buffer_size, GFP_KERNEL);
+ if (!read_buffer)
+ return -ENOMEM;
+
+ ret = read_control_message(cc, read_buffer, buffer_size);
+ if (ret < 0)
+ return ret;
+
+ message_length = ret - CC33XX_NAB_EXTRA_BYTES;
+ message = read_buffer + sizeof(struct nab_header) + CC33XX_NAB_EXTRA_BYTES;
+ ret = parse_control_message(cc, message, message_length);
+ if (ret < 0)
+ return ret;
+
+ /* Each read transaction always carries an updated core status */
+ previous_hint = core_status->host_interrupt_status;
+ new_core_status = (struct core_status *)
+ (read_buffer + buffer_size - sizeof(struct core_status));
+ memcpy(core_status, new_core_status, sizeof(*core_status));
+ /* Host interrupt filed is clear-on-read and we do not want
+ * to overrun previously unhandled bits.
+ */
+ core_status->host_interrupt_status |= previous_hint;
+
+ return ret;
+}
+
+static int verify_padding(struct cc33xx *cc)
+{
+ unsigned int i;
+ const u32 valid_padding = 0x55555555;
+ struct core_status *core_status = cc->core_status;
+
+ for (i = 0; i < ARRAY_SIZE(core_status->block_pad); i++) {
+ if (le32_to_cpu(core_status->block_pad[i]) != valid_padding) {
+ dev_err(cc->dev, "Error in core status padding:\n");
+ print_hex_dump(KERN_DEBUG, "\n", DUMP_PREFIX_OFFSET, 16,
+ 1, core_status, sizeof(*core_status),
+ false);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int process_core_status(struct cc33xx *cc,
+ struct core_status *core_status)
+{
+ bool core_status_idle;
+ u32 shadow_host_interrupt_status;
+ int ret;
+
+ do {
+ core_status_idle = true;
+
+ shadow_host_interrupt_status =
+ le32_to_cpu(core_status->host_interrupt_status);
+
+ /* Interrupts are aggregated (ORed) in this filed with each
+ * read operation from the device.
+ */
+ core_status->host_interrupt_status = 0;
+
+ cc33xx_debug(cc->dev, DEBUG_IRQ,
+ "HINT_STATUS: 0x%x, TSF: 0x%x, rx status: 0x%x\n",
+ shadow_host_interrupt_status, core_status->tsf,
+ core_status->rx_status);
+
+ if (shadow_host_interrupt_status & HINT_COMMAND_COMPLETE) {
+ ret = process_event_and_cmd_result(cc, core_status);
+ if (ret < 0) {
+ memset(core_status, 0, sizeof(*core_status));
+ return ret;
+ }
+ core_status_idle = false;
+ }
+
+ if (le32_get_bits(core_status->rx_status, RX_BYTE_COUNT_MASK) != 0)
+ queue_work(cc->freezable_wq, &cc->irq_deferred_work);
+
+ if (core_status->fw_info.tx_result_queue_index != cc->last_fw_rls_idx)
+ queue_work(cc->freezable_wq, &cc->irq_deferred_work);
+
+ if (shadow_host_interrupt_status & HINT_NEW_TX_RESULT)
+ queue_work(cc->freezable_wq, &cc->irq_deferred_work);
+
+ if (shadow_host_interrupt_status & BOOT_TIME_INTERRUPTS)
+ cc33xx_handle_boot_irqs(cc, shadow_host_interrupt_status);
+
+ if (shadow_host_interrupt_status & HINT_GENERAL_ERROR) {
+ dev_err(cc->dev, "FW is stuck, triggering recovery\n");
+ cc33xx_queue_recovery_work(cc);
+ }
+ } while (!core_status_idle);
+
+ return 0;
+}
+
+void cc33xx_irq(void *cookie)
+{
+ struct cc33xx *cc = cookie;
+ int ret;
+
+ claim_core_status_lock(cc);
+
+ if (test_bit(CC33XX_FLAG_SUSPENDED, &cc->flags)) {
+ /* don't enqueue a work right now. mark it as pending */
+ set_bit(CC33XX_FLAG_PENDING_WORK, &cc->flags);
+ scoped_guard(spinlock_irqsave, &cc->cc_lock) {
+ cc33xx_disable_interrupts_nosync(cc);
+ pm_wakeup_hard_event(cc->dev);
+ }
+ goto out;
+ }
+
+ ret = read_core_status(cc, cc->core_status);
+ if (unlikely(ret < 0)) {
+ dev_err(cc->dev, "IO error during core status read\n");
+ cc33xx_queue_recovery_work(cc);
+ goto out;
+ }
+
+ ret = verify_padding(cc);
+ if (unlikely(ret < 0)) {
+ cc33xx_queue_recovery_work(cc);
+ goto out;
+ }
+
+ process_core_status(cc, cc->core_status);
+
+out:
+ release_core_status_lock(cc);
+}
+
+struct vif_counter_data {
+ u8 counter;
+
+ struct ieee80211_vif *cur_vif;
+ bool cur_vif_running;
+};
+
+static void cc33xx_vif_count_iter(void *data, u8 *mac,
+ struct ieee80211_vif *vif)
+{
+ struct vif_counter_data *counter = data;
+
+ counter->counter++;
+ if (counter->cur_vif == vif)
+ counter->cur_vif_running = true;
+}
+
+static void cc33xx_get_vif_count(struct ieee80211_hw *hw,
+ struct ieee80211_vif *cur_vif,
+ struct vif_counter_data *data)
+{
+ memset(data, 0, sizeof(*data));
+ data->cur_vif = cur_vif;
+
+ ieee80211_iterate_active_interfaces(hw, IEEE80211_IFACE_ITER_RESUME_ALL,
+ cc33xx_vif_count_iter, data);
+}
+
+void cc33xx_queue_recovery_work(struct cc33xx *cc)
+{
+ /* Avoid a recursive recovery */
+ if (!test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags)) {
+ set_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags);
+ queue_work(cc->freezable_wq, &cc->recovery_work);
+ }
+}
+
+/* save the last used PN in the private part of iee80211_sta,
+ * in case of recovery/suspend
+ */
+static void cc33xx_save_freed_pkts(struct cc33xx *cc, u8 hlid,
+ struct cc33xx_station *wl_sta)
+{
+ u32 sqn_recovery_padding = CC33XX_TX_SQN_POST_RECOVERY_PADDING;
+
+ wl_sta->total_freed_pkts = cc->links[hlid].total_freed_pkts;
+
+ /* increment the initial seq number on recovery to account for
+ * transmitted packets that we haven't yet got in the FW status
+ */
+ if (test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags))
+ wl_sta->total_freed_pkts += sqn_recovery_padding;
+}
+
+static void cc33xx_free_wlsta_info(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ u8 hlid, const u8 *addr)
+{
+ struct ieee80211_sta *sta;
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+
+ if (WARN_ON(hlid == CC33XX_INVALID_LINK_ID ||
+ is_zero_ether_addr(addr)))
+ return;
+
+ rcu_read_lock();
+ sta = ieee80211_find_sta(vif, addr);
+
+ if (sta) {
+ struct cc33xx_station *wl_sta = (void *)sta->drv_priv;
+
+ /* In case of recovery, clear the in_connection details, since
+ * HW restart will re-add them for the same states.
+ */
+ if (test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags))
+ cc33xx_update_inconn_sta(cc, wlvif, wl_sta, false);
+
+ cc33xx_save_freed_pkts(cc, hlid, wl_sta);
+ }
+
+ rcu_read_unlock();
+}
+
+static void cc33xx_recovery_work(struct work_struct *work)
+{
+ struct cc33xx *cc = container_of(work, struct cc33xx, recovery_work);
+ struct cc33xx_vif *wlvif;
+ struct ieee80211_vif *vif;
+
+ dev_notice(cc->dev, "CC33xx driver attempting recovery\n");
+
+ if (cc->conf.core.no_recovery) {
+ dev_info(cc->dev, "Recovery disabled by configuration, driver will not restart.\n");
+ return;
+ }
+
+ if (test_bit(CC33XX_FLAG_DRIVER_REMOVED, &cc->flags)) {
+ dev_info(cc->dev, "Driver being removed, recovery disabled\n");
+ return;
+ }
+
+ if (!cc->mac80211_registered) {
+ dev_err(cc->dev, "Fatal error during driver init, cannot recover\n");
+ cc->state = CC33XX_STATE_OFF;
+ cc33xx_disable_interrupts_nosync(cc);
+ return;
+ }
+
+ set_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags);
+
+ wiphy_lock(cc->hw->wiphy);
+
+ scoped_guard(mutex, &cc->mutex)
+ cc->state = CC33XX_STATE_RESTARTING;
+
+ while (!list_empty(&cc->wlvif_list)) {
+ wlvif = list_first_entry(&cc->wlvif_list,
+ struct cc33xx_vif, list);
+ vif = cc33xx_wlvif_to_vif(wlvif);
+
+ if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ ieee80211_connection_loss(vif);
+
+ __cc33xx_op_remove_interface(cc, vif);
+ }
+ wiphy_unlock(cc->hw->wiphy);
+
+ cc33xx_turn_off(cc);
+ msleep(500);
+
+ if (!cc33xx_init_fw(cc))
+ ieee80211_restart_hw(cc->hw);
+
+ clear_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags);
+
+ dev_notice(cc->dev, "CC33xx driver recovery complete\n");
+}
+
+static void irq_deferred_work(struct work_struct *work)
+{
+ int ret;
+ struct cc33xx *cc =
+ container_of(work, struct cc33xx, irq_deferred_work);
+
+ ret = cc33xx_irq_work(cc);
+ if (ret)
+ cc33xx_queue_recovery_work(cc);
+}
+
+static void irq_wrapper(struct platform_device *pdev)
+{
+ struct cc33xx *cc = platform_get_drvdata(pdev);
+
+ cc33xx_irq(cc);
+}
+
+static int cc33xx_plt_init(struct cc33xx *cc)
+{
+ /* PLT init: Role enable + Role start + plt Init */
+ int ret = 0;
+
+ /* Role enable */
+ u8 returned_role_id = CC33XX_INVALID_ROLE_ID;
+
+ ret = cc33xx_cmd_role_enable(cc, bcast_addr,
+ ROLE_TRANSCEIVER, &returned_role_id);
+ if (ret < 0) {
+ dev_info(cc->dev, "PLT init Role Enable FAILED! , PLT roleID is: %u\n",
+ returned_role_id);
+ return ret;
+ }
+
+ ret = cc33xx_cmd_role_start_transceiver(cc, returned_role_id);
+ if (ret < 0) {
+ dev_info(cc->dev, "PLT init Role Start FAILED! , PLT roleID is: %u\n",
+ returned_role_id);
+ cc33xx_cmd_role_disable(cc, &returned_role_id);
+ return ret;
+ }
+
+ cc->plt_role_id = returned_role_id;
+ ret = cc33xx_cmd_plt_enable(cc);
+
+ if (ret >= 0)
+ dev_info(cc->dev, "PLT init Role Start succeed!, PLT roleID is: %u\n",
+ returned_role_id);
+ else
+ dev_info(cc->dev, "PLT init Role Start FAILED! , PLT roleID is: %u\n",
+ returned_role_id);
+
+ return ret;
+}
+
+int cc33xx_plt_start(struct cc33xx *cc, const enum plt_mode plt_mode)
+{
+ int ret = 0;
+
+ if (plt_mode == PLT_ON && cc->plt_mode == PLT_ON) {
+ dev_err(cc->dev, "PLT already on\n");
+ return ret;
+ }
+
+ dev_notice(cc->dev, "PLT start\n");
+
+ if (plt_mode != PLT_CHIP_AWAKE) {
+ ret = cc33xx_plt_init(cc);
+ if (ret < 0) {
+ dev_err(cc->dev, "PLT start failed\n");
+ return ret;
+ }
+ }
+
+ /* Indicate to lower levels that we are now in PLT mode */
+ cc->plt = true;
+ cc->plt_mode = plt_mode;
+
+ return ret;
+}
+
+int cc33xx_plt_stop(struct cc33xx *cc)
+{
+ int ret = 0;
+
+ dev_notice(cc->dev, "PLT stop\n");
+
+ ret = cc33xx_cmd_role_stop_transceiver(cc);
+ if (ret < 0)
+ return ret;
+
+ ret = cc33xx_cmd_role_disable(cc, &cc->plt_role_id);
+ if (ret < 0)
+ return ret;
+
+ cc33xx_cmd_plt_disable(cc);
+
+ cc33xx_flush_deferred_work(cc);
+
+ flush_deferred_event_list(cc);
+
+ cc->plt = false;
+ cc->plt_mode = PLT_OFF;
+ cc->rx_counter = 0;
+
+ return ret;
+}
+
+static void cc33xx_op_tx(struct ieee80211_hw *hw,
+ struct ieee80211_tx_control *control,
+ struct sk_buff *skb)
+{
+ struct cc33xx *cc = hw->priv;
+ struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+ struct ieee80211_vif *vif = info->control.vif;
+ struct cc33xx_vif *wlvif = NULL;
+ u8 hlid;
+
+ if (!vif) {
+ ieee80211_free_txskb(hw, skb);
+ return;
+ }
+
+ guard(spinlock_irqsave)(&cc->cc_lock);
+
+ wlvif = cc33xx_vif_to_data(vif);
+
+ hlid = cc33xx_tx_get_hlid(cc, wlvif, skb, control->sta);
+
+ /* drop the packet if the link is invalid */
+ if (hlid == CC33XX_INVALID_LINK_ID ||
+ !test_bit(hlid, wlvif->links_map)) {
+ cc33xx_debug(cc->dev, DEBUG_TX, "DROP skb hlid %d\n", hlid);
+ ieee80211_free_txskb(hw, skb);
+ return;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_TX, "queue skb hlid %d len %d %p\n",
+ hlid, skb->len, skb);
+ skb_queue_tail(&cc->links[hlid].tx_pending, skb);
+
+ if (!test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags) &&
+ !test_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags)) {
+ cc33xx_debug(cc->dev, DEBUG_TX, "op_tx - Triggering tx thread\n");
+ ieee80211_queue_work(cc->hw, &cc->tx_work);
+ } else {
+ set_bit(CC33XX_FLAG_TX_PENDING, &cc->flags);
+ cc33xx_debug(cc->dev, DEBUG_TX, "op_tx - Not triggering tx thread cc->flags 0x%lx\n",
+ cc->flags);
+ }
+}
+
+static void cc33xx_handle_wake_tx_queue(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ struct cc33xx *cc = hw->priv;
+
+ if (!test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags) &&
+ !test_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags)) {
+ cc33xx_debug(cc->dev, DEBUG_TX, "wake_txq - Triggering tx thread\n");
+ ieee80211_queue_work(cc->hw, &cc->tx_work);
+ } else {
+ set_bit(CC33XX_FLAG_TX_PENDING, &cc->flags);
+ cc33xx_debug(cc->dev, DEBUG_TX, "wake_txq - Not triggering tx thread cc->flags 0x%lx\n",
+ cc->flags);
+ }
+}
+
+static int cc33xx_validate_wowlan_pattern(struct cc33xx *cc, struct cfg80211_pkt_pattern *p)
+{
+ int num_fields = 0, in_field = 0, fields_size = 0;
+ int i, pattern_len = 0;
+
+ if (!p->mask) {
+ dev_warn(cc->dev, "No mask in WoWLAN pattern\n");
+ return -EINVAL;
+ }
+
+ /* The pattern is broken up into segments of bytes at different offsets
+ * that need to be checked by the FW filter. Each segment is called
+ * a field in the FW API. We verify that the total number of fields
+ * required for this pattern won't exceed FW limits (8)
+ * as well as the total fields buffer won't exceed the FW limit.
+ * Note that if there's a pattern which crosses Ethernet/IP header
+ * boundary a new field is required.
+ */
+ for (i = 0; i < p->pattern_len; i++) {
+ if (test_bit(i, (unsigned long *)p->mask)) {
+ if (!in_field) {
+ in_field = 1;
+ pattern_len = 1;
+ } else if (i == ETH_HLEN) {
+ num_fields++;
+ fields_size += pattern_len +
+ RX_FILTER_FIELD_OVERHEAD;
+ pattern_len = 1;
+ } else {
+ pattern_len++;
+ }
+ } else if (in_field) {
+ in_field = 0;
+ fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD;
+ num_fields++;
+ }
+ }
+
+ if (in_field) {
+ fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD;
+ num_fields++;
+ }
+
+ if (num_fields > CC33XX_RX_FILTER_MAX_FIELDS) {
+ dev_warn(cc->dev, "RX Filter too complex. Too many segments\n");
+ return -EINVAL;
+ }
+
+ if (fields_size > RX_FILTER_MAX_FIELDS_SIZE) {
+ dev_warn(cc->dev, "RX filter pattern is too big\n");
+ return -E2BIG;
+ }
+
+ return 0;
+}
+
+static void cc33xx_rx_filter_free(struct cc33xx_rx_filter *filter)
+{
+ int i;
+
+ if (!filter)
+ return;
+
+ for (i = 0; i < filter->num_fields; i++)
+ kfree(filter->fields[i].pattern);
+
+ kfree(filter);
+}
+
+static int cc33xx_rx_filter_alloc_field(struct cc33xx_rx_filter *filter,
+ u16 offset, u8 flags,
+ const u8 *pattern, u8 len)
+{
+ struct cc33xx_rx_filter_field *field;
+
+ if (filter->num_fields == CC33XX_RX_FILTER_MAX_FIELDS) {
+ pr_warn("cc33xx: Max fields per RX filter. can't alloc another\n");
+ return -EINVAL;
+ }
+
+ field = &filter->fields[filter->num_fields];
+
+ field->pattern = kzalloc(len, GFP_KERNEL);
+ if (!field->pattern)
+ return -ENOMEM;
+
+ filter->num_fields++;
+
+ field->offset = cpu_to_le16(offset);
+ field->flags = flags;
+ field->len = len;
+ memcpy(field->pattern, pattern, len);
+
+ return 0;
+}
+
+/* Allocates an RX filter returned through f
+ * which needs to be freed using rx_filter_free()
+ */
+static struct cc33xx_rx_filter *
+cc33xx_convert_wowlan_pattern_to_rx_filter(struct cfg80211_pkt_pattern *p)
+{
+ int i, j, ret = 0;
+ struct cc33xx_rx_filter *filter;
+ u16 offset;
+ u8 flags, len;
+
+ filter = kzalloc_obj(*filter);
+ if (!filter)
+ return ERR_PTR(-ENOMEM);
+
+ i = 0;
+ while (i < p->pattern_len) {
+ if (!test_bit(i, (unsigned long *)p->mask)) {
+ i++;
+ continue;
+ }
+
+ for (j = i; j < p->pattern_len; j++) {
+ if (!test_bit(j, (unsigned long *)p->mask))
+ break;
+
+ if (i < ETH_HLEN &&
+ j >= ETH_HLEN)
+ break;
+ }
+
+ if (i < ETH_HLEN) {
+ offset = i;
+ flags = CC33XX_RX_FILTER_FLAG_ETHERNET_HEADER;
+ } else {
+ offset = i - ETH_HLEN;
+ flags = CC33XX_RX_FILTER_FLAG_IP_HEADER;
+ }
+
+ len = j - i;
+
+ ret = cc33xx_rx_filter_alloc_field(filter, offset, flags,
+ &p->pattern[i], len);
+ if (ret) {
+ cc33xx_rx_filter_free(filter);
+ return ERR_PTR(ret);
+ }
+
+ i = j;
+ }
+ filter->action = FILTER_SIGNAL;
+
+ return filter;
+}
+
+static int cc33xx_configure_wowlan(struct cc33xx *cc,
+ struct cfg80211_wowlan *wow)
+{
+ int i, ret;
+
+ if (!wow || (!wow->any && !wow->n_patterns)) {
+ if (wow)
+ dev_warn(cc->dev, "invalid wow configuration - set to pattern trigger without setting pattern\n");
+
+ ret = cc33xx_acx_default_rx_filter_enable(cc, 0,
+ FILTER_SIGNAL);
+ if (ret)
+ return ret;
+
+ ret = cc33xx_rx_filter_clear_all(cc);
+ if (ret)
+ return ret;
+
+ return 0;
+ }
+
+ if (wow->any) {
+ ret = cc33xx_acx_default_rx_filter_enable(cc, 1,
+ FILTER_SIGNAL);
+ if (ret)
+ return ret;
+
+ ret = cc33xx_rx_filter_clear_all(cc);
+ if (ret)
+ return ret;
+
+ return 0;
+ }
+
+ if (WARN_ON(wow->n_patterns > CC33XX_MAX_RX_FILTERS))
+ return -EINVAL;
+
+ /* Validate all incoming patterns before clearing current FW state */
+ for (i = 0; i < wow->n_patterns; i++) {
+ ret = cc33xx_validate_wowlan_pattern(cc, &wow->patterns[i]);
+ if (ret) {
+ dev_warn(cc->dev, "Bad wowlan pattern %d\n", i);
+ return ret;
+ }
+ }
+
+ ret = cc33xx_acx_default_rx_filter_enable(cc, 0, FILTER_SIGNAL);
+ if (ret)
+ return ret;
+
+ ret = cc33xx_rx_filter_clear_all(cc);
+ if (ret)
+ return ret;
+
+ /* Translate WoWLAN patterns into filters */
+ for (i = 0; i < wow->n_patterns; i++) {
+ struct cfg80211_pkt_pattern *p;
+ struct cc33xx_rx_filter *filter = NULL;
+
+ p = &wow->patterns[i];
+
+ filter = cc33xx_convert_wowlan_pattern_to_rx_filter(p);
+ if (IS_ERR(filter)) {
+ dev_warn(cc->dev, "Failed to create an RX filter from wowlan pattern %d\n",
+ i);
+ return PTR_ERR(filter);
+ }
+
+ ret = cc33xx_rx_filter_enable(cc, i, 1, filter);
+
+ cc33xx_rx_filter_free(filter);
+ if (ret)
+ return ret;
+ }
+
+ ret = cc33xx_acx_default_rx_filter_enable(cc, 1, FILTER_DROP);
+
+ return ret;
+}
+
+static int cc33xx_configure_suspend_sta(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ struct cfg80211_wowlan *wow)
+{
+ struct cc33xx_core_conf *core_conf = &cc->conf.core;
+ int ret = 0;
+
+ if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ return 0;
+
+ ret = cc33xx_configure_wowlan(cc, wow);
+ if (ret < 0)
+ return ret;
+
+ if (core_conf->suspend_wake_up_event == core_conf->wake_up_event &&
+ core_conf->suspend_listen_interval == core_conf->listen_interval)
+ return ret;
+
+ ret = cc33xx_acx_wake_up_conditions(cc, core_conf->suspend_wake_up_event,
+ core_conf->suspend_listen_interval);
+ if (ret < 0)
+ dev_err(cc->dev, "suspend: set wake up conditions failed: %d\n", ret);
+
+ return ret;
+}
+
+static int cc33xx_configure_suspend_ap(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ struct cfg80211_wowlan *wow)
+{
+ int ret;
+
+ if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
+ return 0;
+
+ ret = cc33xx_acx_beacon_filter_opt(cc, wlvif, true);
+ if (ret < 0)
+ return ret;
+
+ ret = cc33xx_configure_wowlan(cc, wow);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int cc33xx_configure_suspend(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cfg80211_wowlan *wow)
+{
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS)
+ return cc33xx_configure_suspend_sta(cc, wlvif, wow);
+
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+ return cc33xx_configure_suspend_ap(cc, wlvif, wow);
+
+ return 0;
+}
+
+static void cc33xx_configure_resume(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret = 0;
+ bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
+ bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
+ struct cc33xx_core_conf *core_conf = &cc->conf.core;
+
+ if (!is_ap && !is_sta)
+ return;
+
+ if ((is_sta && !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) ||
+ (is_ap && !test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)))
+ return;
+
+ cc33xx_configure_wowlan(cc, NULL);
+
+ if (is_sta) {
+ if (core_conf->suspend_wake_up_event == core_conf->wake_up_event &&
+ core_conf->suspend_listen_interval == core_conf->listen_interval)
+ return;
+
+ ret = cc33xx_acx_wake_up_conditions(cc, core_conf->wake_up_event,
+ core_conf->listen_interval);
+
+ if (ret < 0)
+ dev_err(cc->dev, "resume: wake up conditions failed: %d\n",
+ ret);
+
+ } else if (is_ap) {
+ cc33xx_acx_beacon_filter_opt(cc, wlvif, false);
+ }
+}
+
+static int __maybe_unused cc33xx_op_suspend(struct ieee80211_hw *hw,
+ struct cfg80211_wowlan *wow)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif;
+ int ret = 0;
+
+ WARN_ON(!wow);
+
+ /* we want to perform the recovery before suspending */
+ if (test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags)) {
+ dev_warn(cc->dev, "postponing suspend to perform recovery\n");
+ return -EBUSY;
+ }
+
+ cc->keep_device_power = true;
+ cc33xx_for_each_wlvif(cc, wlvif) {
+ if (cc33xx_is_p2p_mgmt(wlvif))
+ continue;
+
+ ret = cc33xx_configure_suspend(cc, wlvif, wow);
+ if (ret < 0) {
+ dev_warn(cc->dev, "couldn't prepare device to suspend\n");
+ return ret;
+ }
+ }
+
+ if (ret < 0) {
+ dev_warn(cc->dev, "couldn't prepare device to suspend\n");
+ return ret;
+ }
+
+ flush_work(&cc->tx_work);
+
+ /* set suspended flag to avoid triggering a new threaded_irq
+ * work.
+ */
+ scoped_guard(spinlock_irqsave, &cc->cc_lock)
+ set_bit(CC33XX_FLAG_SUSPENDED, &cc->flags);
+
+ return 0;
+}
+
+static int __maybe_unused cc33xx_op_resume(struct ieee80211_hw *hw)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif;
+ bool run_irq_work = false, pending_recovery;
+
+ WARN_ON(!cc->keep_device_power);
+
+ /* re-enable irq_work enqueuing, and call irq_work directly if
+ * there is a pending work.
+ */
+ scoped_guard(spinlock_irqsave, &cc->cc_lock) {
+ clear_bit(CC33XX_FLAG_SUSPENDED, &cc->flags);
+ run_irq_work = test_and_clear_bit(CC33XX_FLAG_PENDING_WORK, &cc->flags);
+ }
+
+ /* test the recovery flag before calling any SDIO functions */
+ pending_recovery = test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS,
+ &cc->flags);
+
+ if (run_irq_work) {
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "Running postponed irq_work\n");
+
+ /* don't talk to the HW if recovery is pending */
+ if (!pending_recovery)
+ queue_work(cc->freezable_wq, &cc->irq_deferred_work);
+
+ cc33xx_enable_interrupts(cc);
+ }
+
+ if (pending_recovery) {
+ dev_warn(cc->dev, "queuing forgotten recovery on resume\n");
+ queue_work(cc->freezable_wq, &cc->recovery_work);
+ goto out;
+ }
+
+ cc33xx_for_each_wlvif(cc, wlvif) {
+ if (cc33xx_is_p2p_mgmt(wlvif))
+ continue;
+
+ cc33xx_configure_resume(cc, wlvif);
+ }
+
+out:
+ cc->keep_device_power = false;
+
+ /* Set a flag to re-init the watchdog on the first Tx after resume.
+ * That way we avoid possible conditions where Tx-complete interrupts
+ * fail to arrive and we perform a spurious recovery.
+ */
+ set_bit(CC33XX_FLAG_REINIT_TX_WDOG, &cc->flags);
+
+ return 0;
+}
+
+static int cc33xx_op_start(struct ieee80211_hw *hw)
+{
+ /* We have to delay the booting of the hardware because
+ * we need to know the local MAC address before downloading and
+ * initializing the firmware. The MAC address cannot be changed
+ * after boot, and without the proper MAC address, the firmware
+ * will not function properly.
+ *
+ * The MAC address is first known when the corresponding interface
+ * is added. That is where we will initialize the hardware.
+ */
+
+ return 0;
+}
+
+static void cc33xx_turn_off(struct cc33xx *cc)
+{
+ int i;
+
+ if (cc->state == CC33XX_STATE_OFF) {
+ if (test_and_clear_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS,
+ &cc->flags))
+ cc33xx_enable_interrupts(cc);
+
+ return;
+ }
+
+ wiphy_lock(cc->hw->wiphy);
+ mutex_lock(&cc->mutex);
+
+ /* this must be before the cancel_work calls below, so that the work
+ * functions don't perform further work.
+ */
+ cc->state = CC33XX_STATE_OFF;
+
+ /* Use the nosync variant to disable interrupts, so the mutex could be
+ * held while doing so without deadlocking.
+ */
+ cc33xx_disable_interrupts_nosync(cc);
+
+ wiphy_delayed_work_cancel(cc->hw->wiphy, &cc->scan_complete_work);
+
+ mutex_unlock(&cc->mutex);
+ wiphy_unlock(cc->hw->wiphy);
+
+ if (!test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags))
+ cancel_work_sync(&cc->recovery_work);
+ cc33xx_flush_deferred_work(cc);
+ cancel_work_sync(&cc->netstack_work);
+ cancel_work_sync(&cc->tx_work);
+ cancel_work_sync(&cc->irq_deferred_work);
+
+ /* let's notify MAC80211 about the remaining pending TX frames */
+ mutex_lock(&cc->mutex);
+ cc33xx_tx_reset(cc);
+
+ cc33xx_power_off(cc);
+
+ cc->rx_counter = 0;
+ cc->tx_blocks_available = 0;
+ cc->tx_allocated_blocks = 0;
+
+ cc->sleep_auth = CC33XX_PSM_ILLEGAL;
+ cc->ba_rx_session_count = 0;
+ memset(cc->roles_map, 0, sizeof(cc->roles_map));
+ memset(cc->links_map, 0, sizeof(cc->links_map));
+ memset(cc->roc_map, 0, sizeof(cc->roc_map));
+ memset(cc->session_ids, 0, sizeof(cc->session_ids));
+ memset(cc->rx_filter_enabled, 0, sizeof(cc->rx_filter_enabled));
+ cc->active_sta_count = 0;
+ cc->active_link_count = 0;
+ cc->ble_enable = 0;
+
+ /* The system link is always allocated */
+ cc->links[CC33XX_SYSTEM_HLID].allocated_pkts = 0;
+ cc->links[CC33XX_SYSTEM_HLID].prev_freed_pkts = 0;
+ __set_bit(CC33XX_SYSTEM_HLID, cc->links_map);
+
+ /* this is performed after the cancel_work calls and the associated
+ * mutex_lock, so that cc33xx_op_add_interface does not accidentally
+ * get executed before all these vars have been reset.
+ */
+ cc->flags = 0;
+
+ for (i = 0; i < NUM_TX_QUEUES; i++)
+ cc->tx_allocated_pkts[i] = 0;
+
+ kfree(cc->target_mem_map);
+ cc->target_mem_map = NULL;
+
+ mutex_unlock(&cc->mutex);
+}
+
+static void cc33xx_op_stop(struct ieee80211_hw *hw, bool suspend) {}
+
+static void cc33xx_channel_switch_work(struct wiphy *wiphy,
+ struct wiphy_work *work)
+
+{
+ struct cc33xx *cc;
+ struct ieee80211_vif *vif;
+ struct cc33xx_vif *wlvif;
+
+ wlvif = container_of(work, struct cc33xx_vif, channel_switch_work.work);
+ cc = wlvif->cc;
+
+ dev_info(cc->dev, "channel switch failed (role_id: %d).\n", wlvif->role_id);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ /* check the channel switch is still ongoing */
+ if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags))
+ return;
+
+ vif = cc33xx_wlvif_to_vif(wlvif);
+ ieee80211_chswitch_done(vif, false, 0);
+
+ cc33xx_cmd_stop_channel_switch(cc, wlvif);
+}
+
+static void cc33xx_connection_loss_work(struct wiphy *wiphy,
+ struct wiphy_work *work)
+
+{
+ struct cc33xx *cc;
+ struct ieee80211_vif *vif;
+ struct cc33xx_vif *wlvif;
+
+ wlvif = container_of(work, struct cc33xx_vif,
+ connection_loss_work.work);
+ cc = wlvif->cc;
+
+ dev_info(cc->dev, "Connection loss work (role_id: %d).\n", wlvif->role_id);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ /* Call mac80211 connection loss */
+ if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ return;
+
+ vif = cc33xx_wlvif_to_vif(wlvif);
+ ieee80211_connection_loss(vif);
+}
+
+static void cc33xx_roc_timeout_work(struct wiphy *wiphy,
+ struct wiphy_work *work)
+{
+ struct cc33xx *cc;
+ struct cc33xx_vif *wlvif;
+
+ wlvif = container_of(work, struct cc33xx_vif, roc_timeout_work.work);
+ cc = wlvif->cc;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ if (test_bit(wlvif->role_id, cc->roc_map))
+ cc33xx_croc(cc, wlvif->role_id);
+}
+
+static int cc33xx_allocate_rate_policy(struct cc33xx *cc, u8 *idx)
+{
+ u8 policy = find_first_zero_bit(cc->rate_policies_map,
+ CC33XX_MAX_RATE_POLICIES);
+ if (policy >= CC33XX_MAX_RATE_POLICIES)
+ return -EBUSY;
+
+ __set_bit(policy, cc->rate_policies_map);
+ *idx = policy;
+ return 0;
+}
+
+static void cc33xx_free_rate_policy(struct cc33xx *cc, u8 *idx)
+{
+ if (WARN_ON(*idx >= CC33XX_MAX_RATE_POLICIES))
+ return;
+
+ __clear_bit(*idx, cc->rate_policies_map);
+ *idx = CC33XX_MAX_RATE_POLICIES;
+}
+
+static u8 cc33xx_get_role_type(struct cc33xx_vif *wlvif)
+{
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+
+ switch (wlvif->bss_type) {
+ case BSS_TYPE_AP_BSS:
+ if (wlvif->p2p)
+ return CC33XX_ROLE_P2P_GO;
+ else if (ieee80211_vif_is_mesh(vif))
+ return CC33XX_ROLE_MESH_POINT;
+ return CC33XX_ROLE_AP;
+
+ case BSS_TYPE_STA_BSS:
+ if (wlvif->p2p)
+ return CC33XX_ROLE_P2P_CL;
+ return CC33XX_ROLE_STA;
+ default:
+ dev_err(wlvif->cc->dev, "invalid bss_type: %d\n", wlvif->bss_type);
+ }
+ return CC33XX_INVALID_ROLE_TYPE;
+}
+
+static int cc33xx_init_vif_data(struct cc33xx *cc, struct ieee80211_vif *vif)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct conf_tx_settings *tx_settings = &cc->conf.host_conf.tx;
+ int i;
+
+ /* clear everything but the persistent data */
+ memset(wlvif, 0, offsetof(struct cc33xx_vif, persistent));
+
+ switch (ieee80211_vif_type_p2p(vif)) {
+ case NL80211_IFTYPE_P2P_CLIENT:
+ wlvif->p2p = 1;
+ fallthrough;
+ case NL80211_IFTYPE_STATION:
+ case NL80211_IFTYPE_P2P_DEVICE:
+ wlvif->bss_type = BSS_TYPE_STA_BSS;
+ break;
+ case NL80211_IFTYPE_P2P_GO:
+ wlvif->p2p = 1;
+ fallthrough;
+ case NL80211_IFTYPE_AP:
+ case NL80211_IFTYPE_MESH_POINT:
+ wlvif->bss_type = BSS_TYPE_AP_BSS;
+ break;
+ default:
+ wlvif->bss_type = MAX_BSS_TYPE;
+ return -EOPNOTSUPP;
+ }
+
+ wlvif->role_id = CC33XX_INVALID_ROLE_ID;
+ wlvif->dev_role_id = CC33XX_INVALID_ROLE_ID;
+ wlvif->dev_hlid = CC33XX_INVALID_LINK_ID;
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
+ /* init sta data */
+ wlvif->sta.hlid = CC33XX_INVALID_LINK_ID;
+ cc33xx_allocate_rate_policy(cc, &wlvif->sta.basic_rate_idx);
+ cc33xx_allocate_rate_policy(cc, &wlvif->sta.ap_rate_idx);
+ cc33xx_allocate_rate_policy(cc, &wlvif->sta.p2p_rate_idx);
+ wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
+ wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
+ wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
+ } else {
+ /* init ap data */
+ wlvif->ap.bcast_hlid = CC33XX_INVALID_LINK_ID;
+ wlvif->ap.global_hlid = CC33XX_INVALID_LINK_ID;
+ cc33xx_allocate_rate_policy(cc, &wlvif->ap.mgmt_rate_idx);
+ cc33xx_allocate_rate_policy(cc, &wlvif->ap.bcast_rate_idx);
+ for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
+ cc33xx_allocate_rate_policy(cc,
+ &wlvif->ap.ucast_rate_idx[i]);
+ wlvif->basic_rate_set = CONF_TX_ENABLED_RATES;
+ /* TODO: check if basic_rate shouldn't be
+ * cc33xx_tx_min_rate_get(cc, wlvif->basic_rate_set);
+ * instead (the same thing for STA above).
+ */
+ wlvif->basic_rate = CONF_TX_ENABLED_RATES;
+ /* TODO: this seems to be used only for STA, check it */
+ wlvif->rate_set = CONF_TX_ENABLED_RATES;
+ }
+
+ wlvif->bitrate_masks[NL80211_BAND_2GHZ] = tx_settings->basic_rate;
+ wlvif->bitrate_masks[NL80211_BAND_5GHZ] = tx_settings->basic_rate_5;
+ wlvif->beacon_int = CC33XX_DEFAULT_BEACON_INT;
+ wlvif->power_level = CC33XX_MAX_TXPWR;
+
+ wiphy_delayed_work_init(&wlvif->channel_switch_work,
+ cc33xx_channel_switch_work);
+ wiphy_delayed_work_init(&wlvif->connection_loss_work,
+ cc33xx_connection_loss_work);
+ wiphy_delayed_work_init(&wlvif->roc_timeout_work,
+ cc33xx_roc_timeout_work);
+ INIT_LIST_HEAD(&wlvif->list);
+
+ return 0;
+}
+
+struct cc33xx_hw_queue_iter_data {
+ unsigned long hw_queue_map[BITS_TO_LONGS(CC33XX_NUM_MAC_ADDRESSES)];
+
+ /* current vif */
+ struct ieee80211_vif *vif;
+
+ /* is the current vif among those iterated */
+ bool cur_running;
+};
+
+static void cc33xx_hw_queue_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
+{
+ struct cc33xx_hw_queue_iter_data *iter_data = data;
+
+ if (vif->type == NL80211_IFTYPE_P2P_DEVICE ||
+ WARN_ON_ONCE(vif->hw_queue[0] == IEEE80211_INVAL_HW_QUEUE))
+ return;
+
+ if (iter_data->cur_running || vif == iter_data->vif) {
+ iter_data->cur_running = true;
+ return;
+ }
+
+ __set_bit(vif->hw_queue[0] / NUM_TX_QUEUES, iter_data->hw_queue_map);
+}
+
+static int cc33xx_allocate_hw_queue_base(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif)
+{
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+ struct cc33xx_hw_queue_iter_data iter_data = {};
+ int i, q_base;
+
+ if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
+ vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
+ return 0;
+ }
+
+ iter_data.vif = vif;
+
+ /* mark all bits taken by active interfaces */
+ ieee80211_iterate_active_interfaces_mtx(cc->hw,
+ IEEE80211_IFACE_ITER_RESUME_ALL,
+ cc33xx_hw_queue_iter, &iter_data);
+
+ /* the current vif is already running in mac80211 (resume/recovery) */
+ if (iter_data.cur_running) {
+ wlvif->hw_queue_base = vif->hw_queue[0];
+ cc33xx_debug(cc->dev, DEBUG_MAC80211,
+ "using pre-allocated hw queue base %d\n",
+ wlvif->hw_queue_base);
+
+ /* interface type might have changed type */
+ goto adjust_cab_queue;
+ }
+
+ q_base = find_first_zero_bit(iter_data.hw_queue_map,
+ CC33XX_NUM_MAC_ADDRESSES);
+ if (q_base >= CC33XX_NUM_MAC_ADDRESSES)
+ return -EBUSY;
+
+ wlvif->hw_queue_base = q_base * NUM_TX_QUEUES;
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "allocating hw queue base: %d\n",
+ wlvif->hw_queue_base);
+
+ for (i = 0; i < NUM_TX_QUEUES; i++) {
+ cc->queue_stop_reasons[wlvif->hw_queue_base + i] = 0;
+ /* register hw queues in mac80211 */
+ vif->hw_queue[i] = wlvif->hw_queue_base + i;
+ }
+
+adjust_cab_queue:
+ /* the last places are reserved for cab queues per interface */
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
+ vif->cab_queue = NUM_TX_QUEUES * CC33XX_NUM_MAC_ADDRESSES +
+ wlvif->hw_queue_base / NUM_TX_QUEUES;
+ } else {
+ vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
+ }
+
+ return 0;
+}
+
+static int cc33xx_op_add_interface(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct vif_counter_data vif_count;
+ int ret = 0;
+ u8 role_type;
+
+ if (cc->plt) {
+ dev_err(cc->dev, "Adding Interface not allowed while in PLT mode\n");
+ return -EBUSY;
+ }
+
+ vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
+ IEEE80211_VIF_SUPPORTS_UAPSD |
+ IEEE80211_VIF_SUPPORTS_CQM_RSSI;
+
+ cc33xx_get_vif_count(hw, vif, &vif_count);
+
+ /* in some very corner case HW recovery scenarios its possible to
+ * get here before __cc33xx_op_remove_interface is complete, so
+ * opt out if that is the case.
+ */
+ if (test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags) ||
+ test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+ return -EBUSY;
+
+ ret = cc33xx_init_vif_data(cc, vif);
+ if (ret < 0)
+ return ret;
+
+ wlvif->cc = cc;
+ role_type = cc33xx_get_role_type(wlvif);
+ if (role_type == CC33XX_INVALID_ROLE_TYPE)
+ return -EINVAL;
+
+ ret = cc33xx_allocate_hw_queue_base(cc, wlvif);
+ if (ret < 0)
+ return ret;
+
+ if (!cc33xx_is_p2p_mgmt(wlvif)) {
+ ret = cc33xx_cmd_role_enable(cc, vif->addr,
+ role_type, &wlvif->role_id);
+ if (ret < 0)
+ return ret;
+
+ ret = cc33xx_init_vif_specific(cc, vif);
+ if (ret < 0)
+ return ret;
+ } else {
+ ret = cc33xx_cmd_role_enable(cc, vif->addr, CC33XX_ROLE_DEVICE,
+ &wlvif->dev_role_id);
+ if (ret < 0)
+ return ret;
+
+ /* needed mainly for configuring rate policies */
+ ret = cc33xx_acx_config_ps(cc, wlvif);
+ if (ret < 0)
+ return ret;
+ }
+
+ list_add(&wlvif->list, &cc->wlvif_list);
+ set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
+
+ scoped_guard(mutex, &cc->mutex) {
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+ cc->ap_count++;
+ else
+ cc->sta_count++;
+ }
+
+ return ret;
+}
+
+static void __cc33xx_op_remove_interface(struct cc33xx *cc,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int i;
+ bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+
+ if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+ return;
+
+ /* because of hardware recovery, we may get here twice */
+ if (cc->state == CC33XX_STATE_OFF)
+ return;
+
+ if (cc->scan.state != CC33XX_SCAN_STATE_IDLE &&
+ cc->scan_wlvif == wlvif) {
+ struct cfg80211_scan_info info = {
+ .aborted = true,
+ };
+
+ cc->scan.state = CC33XX_SCAN_STATE_IDLE;
+ cc->scan_wlvif = NULL;
+ cc->scan.req = NULL;
+ ieee80211_scan_completed(cc->hw, &info);
+ }
+
+ if (cc->sched_vif == wlvif)
+ cc->sched_vif = NULL;
+
+ if (cc->roc_vif == vif) {
+ cc->roc_vif = NULL;
+ ieee80211_remain_on_channel_expired(cc->hw);
+ }
+
+ if (!test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags)) {
+ /* disable active roles */
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
+ if (wlvif->dev_hlid != CC33XX_INVALID_LINK_ID)
+ cc33xx_stop_dev(cc, wlvif);
+ }
+
+ if (!cc33xx_is_p2p_mgmt(wlvif))
+ cc33xx_cmd_role_disable(cc, &wlvif->role_id);
+ else
+ cc33xx_cmd_role_disable(cc, &wlvif->dev_role_id);
+ }
+
+ cc33xx_tx_reset_wlvif(cc, wlvif);
+
+ mutex_lock(&cc->mutex);
+ /* clear all hlids (except system_hlid) */
+ wlvif->dev_hlid = CC33XX_INVALID_LINK_ID;
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
+ wlvif->sta.hlid = CC33XX_INVALID_LINK_ID;
+ cc33xx_free_rate_policy(cc, &wlvif->sta.basic_rate_idx);
+ cc33xx_free_rate_policy(cc, &wlvif->sta.ap_rate_idx);
+ cc33xx_free_rate_policy(cc, &wlvif->sta.p2p_rate_idx);
+ } else {
+ wlvif->ap.bcast_hlid = CC33XX_INVALID_LINK_ID;
+ wlvif->ap.global_hlid = CC33XX_INVALID_LINK_ID;
+ cc33xx_free_rate_policy(cc, &wlvif->ap.mgmt_rate_idx);
+ cc33xx_free_rate_policy(cc, &wlvif->ap.bcast_rate_idx);
+ for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
+ cc33xx_free_rate_policy(cc,
+ &wlvif->ap.ucast_rate_idx[i]);
+ cc33xx_free_ap_keys(wlvif);
+ }
+
+ dev_kfree_skb(wlvif->probereq);
+ wlvif->probereq = NULL;
+
+ list_del(&wlvif->list);
+ memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
+ wlvif->role_id = CC33XX_INVALID_ROLE_ID;
+ wlvif->dev_role_id = CC33XX_INVALID_ROLE_ID;
+
+ if (is_ap)
+ cc->ap_count--;
+ else
+ cc->sta_count--;
+ mutex_unlock(&cc->mutex);
+
+ /* Last AP, have more stations. Configure sleep auth according to STA.
+ * Skip it when on unintended recovery.
+ */
+ if (test_bit(CC33XX_FLAG_RECOVERY_IN_PROGRESS, &cc->flags))
+ goto out;
+
+ /* mask ap events */
+ if (cc->ap_count == 0 && is_ap)
+ cc->event_mask &= ~cc->ap_event_mask;
+
+ if (cc->ap_count == 0 && is_ap && cc->sta_count) {
+ u8 sta_auth = cc->conf.host_conf.conn.sta_sleep_auth;
+ /* Configure for power according to debugfs */
+ if (sta_auth != CC33XX_PSM_ILLEGAL)
+ cc33xx_acx_sleep_auth(cc, sta_auth);
+ /* Configure for ELP power saving */
+ else
+ cc33xx_acx_sleep_auth(cc, CC33XX_PSM_ELP);
+ }
+
+out:
+ wiphy_delayed_work_cancel(cc->hw->wiphy, &wlvif->connection_loss_work);
+ wiphy_delayed_work_cancel(cc->hw->wiphy, &wlvif->channel_switch_work);
+ wiphy_delayed_work_cancel(cc->hw->wiphy, &wlvif->roc_timeout_work);
+}
+
+static void cc33xx_op_remove_interface(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct cc33xx_vif *iter;
+ struct vif_counter_data vif_count;
+
+ cc33xx_get_vif_count(hw, vif, &vif_count);
+
+ if (cc->state == CC33XX_STATE_OFF ||
+ !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+ return;
+
+ /* cc->vif can be null here if someone shuts down the interface
+ * just when hardware recovery has been started.
+ */
+ cc33xx_for_each_wlvif(cc, iter) {
+ if (iter != wlvif)
+ continue;
+
+ __cc33xx_op_remove_interface(cc, vif);
+ break;
+ }
+ WARN_ON(iter != wlvif);
+}
+
+static int cc33xx_op_change_interface(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ enum nl80211_iftype new_type, bool p2p)
+{
+ struct cc33xx *cc = hw->priv;
+ int ret;
+
+ set_bit(CC33XX_FLAG_VIF_CHANGE_IN_PROGRESS, &cc->flags);
+ cc33xx_op_remove_interface(hw, vif);
+
+ vif->type = new_type;
+ vif->p2p = p2p;
+ ret = cc33xx_op_add_interface(hw, vif);
+
+ clear_bit(CC33XX_FLAG_VIF_CHANGE_IN_PROGRESS, &cc->flags);
+ return ret;
+}
+
+static int cc33xx_join(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ /* One of the side effects of the JOIN command is that is clears
+ * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
+ * to a WPA/WPA2 access point will therefore kill the data-path.
+ * Currently the only valid scenario for JOIN during association
+ * is on roaming, in which case we will also be given new keys.
+ * Keep the below message for now, unless it starts bothering
+ * users who really like to roam a lot :)
+ */
+ if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ dev_info(cc->dev, "JOIN while associated.\n");
+
+ /* clear encryption type */
+ wlvif->encryption_type = KEY_NONE;
+
+ return cc33xx_cmd_role_start_sta(cc, wlvif);
+}
+
+static int cc33xx_ssid_set(struct cc33xx_vif *wlvif,
+ struct sk_buff *skb, int offset)
+{
+ u8 ssid_len;
+ const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
+ skb->len - offset);
+
+ if (!ptr) {
+ dev_err(wlvif->cc->dev, "No SSID in IEs!\n");
+ return -ENOENT;
+ }
+
+ ssid_len = ptr[1];
+ if (ssid_len > IEEE80211_MAX_SSID_LEN) {
+ dev_err(wlvif->cc->dev, "SSID is too long!\n");
+ return -EINVAL;
+ }
+
+ wlvif->ssid_len = ssid_len;
+ memcpy(wlvif->ssid, ptr + 2, ssid_len);
+ return 0;
+}
+
+static int cc33xx_set_ssid(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+ struct sk_buff *skb;
+ int ieoffset;
+
+ /* we currently only support setting the ssid from the ap probe req */
+ if (wlvif->bss_type != BSS_TYPE_STA_BSS)
+ return -EINVAL;
+
+ skb = ieee80211_ap_probereq_get(cc->hw, vif);
+ if (!skb)
+ return -EINVAL;
+
+ ieoffset = offsetof(struct ieee80211_mgmt, u.probe_req.variable);
+ cc33xx_ssid_set(wlvif, skb, ieoffset);
+ dev_kfree_skb(skb);
+
+ return 0;
+}
+
+static int cc33xx_set_assoc(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_bss_conf *bss_conf,
+ struct ieee80211_sta *sta,
+ struct ieee80211_vif *vif, u32 sta_rate_set)
+{
+ int ret;
+
+ wlvif->aid = vif->cfg.aid;
+ wlvif->channel_type = cfg80211_get_chandef_type(&bss_conf->chanreq.oper);
+ wlvif->beacon_int = bss_conf->beacon_int;
+ wlvif->wmm_enabled = bss_conf->qos;
+
+ wlvif->nontransmitted = bss_conf->nontransmitted;
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "set_assoc mbssid params: nonTxbssid: %d, idx: %d, max_ind: %d, trans_bssid: %pM, ema_ap: %d\n",
+ bss_conf->nontransmitted, bss_conf->bssid_index,
+ bss_conf->bssid_indicator, bss_conf->transmitter_bssid,
+ bss_conf->ema_ap);
+ wlvif->bssid_index = bss_conf->bssid_index;
+ wlvif->bssid_indicator = bss_conf->bssid_indicator;
+ memcpy(wlvif->transmitter_bssid, bss_conf->transmitter_bssid, ETH_ALEN);
+
+ set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
+
+ ret = cc33xx_assoc_info_cfg(cc, wlvif, sta, wlvif->aid);
+ if (ret < 0)
+ return ret;
+
+ if (sta_rate_set)
+ wlvif->rate_set = cc33xx_tx_enabled_rates_get(cc, sta_rate_set,
+ wlvif->band);
+
+ return ret;
+}
+
+static int cc33xx_unset_assoc(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret;
+ bool sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
+
+ /* make sure we are connected (sta) joined */
+ if (sta && !test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
+ &wlvif->flags))
+ return 0;
+
+ if (sta) {
+ /* use defaults when not associated */
+ wlvif->aid = 0;
+
+ /* free probe-request template */
+ dev_kfree_skb(wlvif->probereq);
+ wlvif->probereq = NULL;
+
+ /* disable beacon filtering */
+ ret = cc33xx_acx_beacon_filter_opt(cc, wlvif, false);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+
+ cc33xx_cmd_stop_channel_switch(cc, wlvif);
+ ieee80211_chswitch_done(vif, false, 0);
+ wiphy_delayed_work_cancel(cc->hw->wiphy,
+ &wlvif->channel_switch_work);
+ }
+
+ return 0;
+}
+
+static void cc33xx_set_band_rate(struct cc33xx_vif *wlvif)
+{
+ wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
+ wlvif->rate_set = wlvif->basic_rate_set;
+}
+
+static void cc33xx_sta_handle_idle(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, bool idle)
+{
+ bool cur_idle = !test_bit(WLVIF_FLAG_ACTIVE, &wlvif->flags);
+
+ if (idle == cur_idle)
+ return;
+
+ if (idle) {
+ clear_bit(WLVIF_FLAG_ACTIVE, &wlvif->flags);
+ } else {
+ /* The current firmware only supports sched_scan in idle */
+ if (cc->sched_vif == wlvif)
+ cc33xx_scan_sched_scan_stop(cc, wlvif);
+
+ set_bit(WLVIF_FLAG_ACTIVE, &wlvif->flags);
+ }
+}
+
+struct cc33xx_filter_params {
+ bool enabled;
+ int mc_list_length;
+ u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
+};
+
+static u64 cc33xx_op_prepare_multicast(struct ieee80211_hw *hw,
+ struct netdev_hw_addr_list *mc_list)
+{
+ struct cc33xx_filter_params *fp;
+ struct netdev_hw_addr *ha;
+ struct cc33xx *cc = hw->priv;
+
+ fp = kzalloc_obj(*fp);
+ if (!fp) {
+ dev_err(cc->dev, "Out of memory setting filters.\n");
+ return 0;
+ }
+
+ /* update multicast filtering parameters */
+ fp->mc_list_length = 0;
+ if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
+ fp->enabled = false;
+ } else {
+ fp->enabled = true;
+ netdev_hw_addr_list_for_each(ha, mc_list) {
+ memcpy(fp->mc_list[fp->mc_list_length],
+ ha->addr, ETH_ALEN);
+ fp->mc_list_length++;
+ }
+ }
+
+ return (u64)(unsigned long)fp;
+}
+
+#define CC33XX_SUPPORTED_FILTERS (FIF_ALLMULTI)
+
+static void cc33xx_op_configure_filter(struct ieee80211_hw *hw,
+ unsigned int changed,
+ unsigned int *total, u64 multicast)
+{
+ struct cc33xx_filter_params *fp = (void *)(unsigned long)multicast;
+ struct cc33xx *cc = hw->priv;
+
+ *total &= CC33XX_SUPPORTED_FILTERS;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ goto out;
+
+ if (!fp || !fp->enabled || *total & FIF_ALLMULTI)
+ cc33xx_acx_group_address_tbl(cc, false, NULL, 0);
+ else
+ cc33xx_acx_group_address_tbl(cc, true, fp->mc_list, fp->mc_list_length);
+
+out:
+ kfree(fp);
+}
+
+static int cc33xx_record_ap_key(struct cc33xx_vif *wlvif,
+ u8 id, u8 key_type, u8 key_size, const u8 *key,
+ u8 hlid, u32 tx_seq_32, u16 tx_seq_16)
+{
+ struct cc33xx_ap_key *ap_key;
+ int i;
+
+ if (key_size > MAX_KEY_SIZE)
+ return -EINVAL;
+
+ /* Find next free entry in ap_keys. Also check we are not replacing
+ * an existing key.
+ */
+ for (i = 0; i < MAX_NUM_KEYS; i++) {
+ if (!wlvif->ap.recorded_keys[i])
+ break;
+
+ if (wlvif->ap.recorded_keys[i]->id == id) {
+ dev_warn(wlvif->cc->dev, "trying to record key replacement\n");
+ return -EINVAL;
+ }
+ }
+
+ if (i == MAX_NUM_KEYS)
+ return -EBUSY;
+
+ ap_key = kzalloc_obj(*ap_key);
+ if (!ap_key)
+ return -ENOMEM;
+
+ ap_key->id = id;
+ ap_key->key_type = key_type;
+ ap_key->key_size = key_size;
+ memcpy(ap_key->key, key, key_size);
+ ap_key->hlid = hlid;
+ ap_key->tx_seq_32 = tx_seq_32;
+ ap_key->tx_seq_16 = tx_seq_16;
+
+ wlvif->ap.recorded_keys[i] = ap_key;
+ return 0;
+}
+
+static void cc33xx_free_ap_keys(struct cc33xx_vif *wlvif)
+{
+ int i;
+
+ for (i = 0; i < MAX_NUM_KEYS; i++) {
+ kfree(wlvif->ap.recorded_keys[i]);
+ wlvif->ap.recorded_keys[i] = NULL;
+ }
+}
+
+static int cc33xx_ap_init_hwenc(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int i, ret = 0;
+ struct cc33xx_ap_key *key;
+ bool wep_key_added = false;
+
+ for (i = 0; i < MAX_NUM_KEYS; i++) {
+ u8 hlid;
+
+ if (!wlvif->ap.recorded_keys[i])
+ break;
+
+ key = wlvif->ap.recorded_keys[i];
+ hlid = key->hlid;
+ if (hlid == CC33XX_INVALID_LINK_ID)
+ hlid = wlvif->ap.bcast_hlid;
+
+ ret = cc33xx_cmd_set_ap_key(cc, wlvif, KEY_ADD_OR_REPLACE,
+ key->id, key->key_type,
+ key->key_size, key->key, hlid,
+ key->tx_seq_32, key->tx_seq_16);
+ if (ret < 0)
+ goto out;
+
+ if (key->key_type == KEY_WEP)
+ wep_key_added = true;
+ }
+
+ if (wep_key_added) {
+ ret = cc33xx_cmd_set_default_wep_key(cc, wlvif->default_key,
+ wlvif->ap.bcast_hlid);
+ if (ret < 0)
+ goto out;
+ }
+
+out:
+ cc33xx_free_ap_keys(wlvif);
+ return ret;
+}
+
+static int cc33xx_config_key(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u16 action, u8 id, u8 key_type, u8 key_size,
+ const u8 *key, u32 tx_seq_32, u16 tx_seq_16,
+ struct ieee80211_sta *sta)
+{
+ int ret;
+ bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+
+ if (is_ap) {
+ struct cc33xx_station *wl_sta;
+ u8 hlid;
+
+ if (sta) {
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+ hlid = wl_sta->hlid;
+ } else {
+ hlid = wlvif->ap.bcast_hlid;
+ }
+
+ if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
+ /* We do not support removing keys after AP shutdown.
+ * Pretend we do to make mac80211 happy.
+ */
+ if (action != KEY_ADD_OR_REPLACE)
+ return 0;
+
+ ret = cc33xx_record_ap_key(wlvif, id, key_type,
+ key_size, key, hlid,
+ tx_seq_32, tx_seq_16);
+ } else {
+ ret = cc33xx_cmd_set_ap_key(cc, wlvif, action, id,
+ key_type, key_size, key,
+ hlid, tx_seq_32, tx_seq_16);
+ }
+
+ if (ret < 0)
+ return ret;
+ } else {
+ const u8 *addr = sta ? sta->addr : bcast_addr;
+
+ if (is_zero_ether_addr(addr)) {
+ /* We dont support TX only encryption */
+ return -EOPNOTSUPP;
+ }
+
+ /* The cc33xx does not allow to remove unicast keys - they
+ * will be cleared automatically on next CMD_JOIN. Ignore the
+ * request silently, as we dont want the mac80211 to emit
+ * an error message.
+ */
+ if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
+ return 0;
+
+ /* don't remove key if hlid was already deleted */
+ if (action == KEY_REMOVE &&
+ wlvif->sta.hlid == CC33XX_INVALID_LINK_ID)
+ return 0;
+
+ ret = cc33xx_cmd_set_sta_key(cc, wlvif, action, id, key_type,
+ key_size, key, addr, tx_seq_32,
+ tx_seq_16);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int cc33xx_set_key(struct cc33xx *cc, enum set_key_cmd cmd,
+ struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+ struct ieee80211_key_conf *key_conf)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+ u32 tx_seq_32 = 0;
+ u16 tx_seq_16 = 0;
+ u8 key_type;
+ u8 hlid;
+
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
+ if (sta) {
+ struct cc33xx_station *wl_sta = (void *)sta->drv_priv;
+
+ hlid = wl_sta->hlid;
+ } else {
+ hlid = wlvif->ap.bcast_hlid;
+ }
+ } else {
+ hlid = wlvif->sta.hlid;
+ }
+
+ if (hlid != CC33XX_INVALID_LINK_ID) {
+ u64 tx_seq = cc->links[hlid].total_freed_pkts;
+
+ tx_seq_32 = CC33XX_TX_SECURITY_HI32(tx_seq);
+ tx_seq_16 = CC33XX_TX_SECURITY_LO16(tx_seq);
+ }
+
+ switch (key_conf->cipher) {
+ case WLAN_CIPHER_SUITE_WEP40:
+ case WLAN_CIPHER_SUITE_WEP104:
+ key_type = KEY_WEP;
+ key_conf->hw_key_idx = key_conf->keyidx;
+ break;
+ case WLAN_CIPHER_SUITE_TKIP:
+ key_type = KEY_TKIP;
+ key_conf->hw_key_idx = key_conf->keyidx;
+ break;
+ case WLAN_CIPHER_SUITE_CCMP:
+ key_type = KEY_AES;
+ key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
+ break;
+ case WLAN_CIPHER_SUITE_GCMP:
+ key_type = KEY_GCMP128;
+ key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
+ break;
+ case WLAN_CIPHER_SUITE_CCMP_256:
+ key_type = KEY_CCMP256;
+ key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
+ break;
+ case WLAN_CIPHER_SUITE_GCMP_256:
+ key_type = KEY_GCMP_256;
+ key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
+ break;
+ case WLAN_CIPHER_SUITE_AES_CMAC:
+ key_type = KEY_IGTK;
+ break;
+ case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+ key_type = KEY_CMAC_256;
+ break;
+ case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+ key_type = KEY_GMAC_128;
+ break;
+ case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+ key_type = KEY_GMAC_256;
+ break;
+ default:
+ dev_err(cc->dev, "Unknown key algo 0x%x\n", key_conf->cipher);
+
+ return -EOPNOTSUPP;
+ }
+
+ switch (cmd) {
+ case SET_KEY:
+ ret = cc33xx_config_key(cc, wlvif, KEY_ADD_OR_REPLACE,
+ key_conf->keyidx, key_type, key_conf->keylen,
+ key_conf->key, tx_seq_32, tx_seq_16, sta);
+ if (ret < 0) {
+ dev_err(cc->dev, "Could not add or replace key\n");
+ return ret;
+ }
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
+ (sta || key_type == KEY_WEP))
+ wlvif->encryption_type = key_type;
+ break;
+
+ case DISABLE_KEY:
+ ret = cc33xx_config_key(cc, wlvif, KEY_REMOVE, key_conf->keyidx,
+ key_type, key_conf->keylen,
+ key_conf->key, 0, 0, sta);
+ if (ret < 0) {
+ dev_err(cc->dev, "Could not remove key\n");
+ return ret;
+ }
+ break;
+
+ default:
+ dev_err(cc->dev, "Unsupported key cmd 0x%x\n", cmd);
+ return -EOPNOTSUPP;
+ }
+
+ return ret;
+}
+
+static int cc33xx_hw_set_key(struct cc33xx *cc, enum set_key_cmd cmd,
+ struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+ struct ieee80211_key_conf *key_conf)
+{
+ bool special_enc;
+ int ret;
+
+ special_enc = (key_conf->cipher == WLAN_CIPHER_SUITE_TKIP);
+
+ guard(mutex)(&cc->mutex);
+
+ ret = cc33xx_set_key(cc, cmd, vif, sta, key_conf);
+ if (ret < 0)
+ return ret;
+
+ /* when adding the first or removing the last TKIP key,
+ * we have to adjust the number of spare blocks.
+ */
+ if (special_enc) {
+ if (cmd == SET_KEY) {
+ /* first key */
+ cc->extra_spare_key_count++;
+ } else if (cmd == DISABLE_KEY) {
+ /* last key */
+ cc->extra_spare_key_count--;
+ }
+ }
+
+ return ret;
+}
+
+static int cc33xx_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+ struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta,
+ struct ieee80211_key_conf *key_conf)
+{
+ struct cc33xx *cc = hw->priv;
+ int ret;
+ bool might_change_spare = (key_conf->cipher == WLAN_CIPHER_SUITE_TKIP);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return 0;
+
+ if (might_change_spare) {
+ /* stop the queues and flush to ensure the next packets are
+ * in sync with FW spare block accounting
+ */
+ cc33xx_stop_queues(cc, CC33XX_QUEUE_STOP_REASON_SPARE_BLK);
+ cc33xx_tx_flush(cc);
+ }
+
+ ret = cc33xx_hw_set_key(cc, cmd, vif, sta, key_conf);
+
+ if (might_change_spare)
+ cc33xx_wake_queues(cc, CC33XX_QUEUE_STOP_REASON_SPARE_BLK);
+
+ return ret;
+}
+
+static void cc33xx_op_set_default_key_idx(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ int key_idx)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211,
+ "mac80211 set default key idx %d\n", key_idx);
+
+ /* we don't handle unsetting of default key */
+ if (key_idx == -1)
+ return;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ guard(mutex)(&cc->mutex);
+
+ wlvif->default_key = key_idx;
+
+ /* the default WEP key needs to be configured at least once */
+ if (wlvif->encryption_type == KEY_WEP)
+ cc33xx_cmd_set_default_wep_key(cc, key_idx, wlvif->sta.hlid);
+}
+
+static int cc33xx_op_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_scan_request *hw_req)
+{
+ struct cfg80211_scan_request *req = &hw_req->req;
+ struct cc33xx *cc = hw->priv;
+ int ret;
+ u8 *ssid = NULL;
+ size_t len = 0;
+
+ if (req->n_ssids) {
+ ssid = req->ssids[0].ssid;
+ len = req->ssids[0].ssid_len;
+ }
+
+ if (unlikely(cc->state != CC33XX_STATE_ON)) {
+ /* We cannot return -EBUSY here because cfg80211 will expect
+ * a call to ieee80211_scan_completed if we do - in this case
+ * there won't be any call.
+ */
+ return -EAGAIN;
+ }
+
+ /* fail if there is any role in ROC */
+ if (find_first_bit(cc->roc_map, CC33XX_MAX_ROLES) < CC33XX_MAX_ROLES) {
+ /* don't allow scanning right now */
+ return -EBUSY;
+ }
+
+ ret = cc33xx_scan(hw->priv, vif, ssid, len, req);
+
+ return ret;
+}
+
+static void cc33xx_op_cancel_hw_scan(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct cfg80211_scan_info info = {
+ .aborted = true,
+ };
+ int ret;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ if (cc->scan.state == CC33XX_SCAN_STATE_IDLE)
+ return;
+
+ if (cc->scan.state != CC33XX_SCAN_STATE_DONE) {
+ ret = cc33xx_scan_stop(cc, wlvif);
+ if (ret < 0)
+ return;
+ }
+
+ cc->scan.state = CC33XX_SCAN_STATE_IDLE;
+ cc->scan_wlvif = NULL;
+ cc->scan.req = NULL;
+ ieee80211_scan_completed(cc->hw, &info);
+
+ wiphy_delayed_work_cancel(cc->hw->wiphy, &cc->scan_complete_work);
+}
+
+static int cc33xx_op_sched_scan_start(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct cfg80211_sched_scan_request *req,
+ struct ieee80211_scan_ies *ies)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return -EAGAIN;
+
+ ret = cc33xx_sched_scan_start(cc, wlvif, req, ies);
+ if (!ret)
+ cc->sched_vif = wlvif;
+
+ return ret;
+}
+
+static int cc33xx_op_sched_scan_stop(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return 0;
+
+ cc->sched_vif = NULL;
+
+ cc33xx_scan_sched_scan_stop(cc, wlvif);
+
+ return 0;
+}
+
+static int cc33xx_op_set_frag_threshold(struct ieee80211_hw *hw, int radio_idx,
+ u32 value)
+{
+ return 0;
+}
+
+static int cc33xx_op_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
+ u32 value)
+{
+ return 0;
+}
+
+static int cc33xx_bss_erp_info_changed(struct cc33xx *cc,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *bss_conf,
+ u64 changed)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret = 0;
+
+ if (changed & BSS_CHANGED_ERP_SLOT) {
+ if (bss_conf->use_short_slot)
+ ret = cc33xx_acx_slot(cc, wlvif, SLOT_TIME_SHORT);
+ else
+ ret = cc33xx_acx_slot(cc, wlvif, SLOT_TIME_LONG);
+ if (ret < 0) {
+ dev_warn(cc->dev, "Set slot time failed %d\n", ret);
+ return ret;
+ }
+ }
+
+ if (changed & BSS_CHANGED_ERP_PREAMBLE) {
+ if (bss_conf->use_short_preamble)
+ cc33xx_acx_set_preamble(cc, wlvif, ACX_PREAMBLE_SHORT);
+ else
+ cc33xx_acx_set_preamble(cc, wlvif, ACX_PREAMBLE_LONG);
+ }
+
+ if (changed & BSS_CHANGED_ERP_CTS_PROT) {
+ if (bss_conf->use_cts_prot) {
+ ret = cc33xx_acx_cts_protect(cc, wlvif,
+ CTSPROTECT_ENABLE);
+ } else {
+ ret = cc33xx_acx_cts_protect(cc, wlvif,
+ CTSPROTECT_DISABLE);
+ }
+
+ if (ret < 0) {
+ dev_warn(cc->dev, "Set ctsprotect failed %d\n", ret);
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+static int cc33xx_set_beacon_template(struct cc33xx *cc,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+ int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
+ struct sk_buff *beacon = ieee80211_beacon_get(cc->hw, vif, 0);
+
+ struct cc33xx_cmd_set_beacon_info *cmd __free(kfree) = NULL;
+
+ if (!beacon)
+ return -EINVAL;
+
+ ret = cc33xx_ssid_set(wlvif, beacon, ieoffset);
+ if (ret < 0)
+ goto end_bcn;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd) {
+ ret = -ENOMEM;
+ goto end_bcn;
+ }
+
+ cmd->role_id = wlvif->role_id;
+ cmd->beacon_len = cpu_to_le16(beacon->len);
+
+ memcpy(cmd->beacon, beacon->data, beacon->len);
+
+ ret = cc33xx_cmd_send(cc, CMD_AP_SET_BEACON_INFO, cmd, sizeof(*cmd), 0);
+
+end_bcn:
+ dev_kfree_skb(beacon);
+ return ret;
+}
+
+static int cc33xx_bss_beacon_info_changed(struct cc33xx *cc,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *bss_conf,
+ u32 changed)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+
+ if (changed & BSS_CHANGED_BEACON_INT) {
+ cc33xx_debug(cc->dev, DEBUG_MASTER, "beacon interval updated: %d\n",
+ bss_conf->beacon_int);
+
+ wlvif->beacon_int = bss_conf->beacon_int;
+ }
+
+ if (changed & BSS_CHANGED_BEACON) {
+ ret = cc33xx_set_beacon_template(cc, vif);
+ if (ret < 0) {
+ dev_err(cc->dev, "set beacon template failed: %d\n", ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+/* AP mode changes */
+static void cc33xx_bss_info_changed_ap(struct cc33xx *cc,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *bss_conf,
+ u64 changed)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret = 0;
+
+ if (changed & BSS_CHANGED_BASIC_RATES) {
+ u32 rates = bss_conf->basic_rates;
+ u32 supported_rates = 0;
+
+ wlvif->basic_rate_set = cc33xx_tx_enabled_rates_get(cc, rates,
+ wlvif->band);
+ wlvif->basic_rate = cc33xx_tx_min_rate_get(wlvif->basic_rate_set);
+
+ supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
+ ret = cc33xx_update_ap_rates(cc, wlvif->role_id,
+ wlvif->basic_rate_set,
+ supported_rates);
+
+ ret = cc33xx_set_beacon_template(cc, vif);
+ if (ret < 0)
+ return;
+ }
+
+ ret = cc33xx_bss_beacon_info_changed(cc, vif, bss_conf, changed);
+ if (ret < 0)
+ return;
+
+ if (changed & BSS_CHANGED_BEACON_ENABLED) {
+ if (bss_conf->enable_beacon) {
+ if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
+ ret = cc33xx_cmd_role_start_ap(cc, wlvif);
+ if (ret < 0)
+ return;
+
+ ret = cc33xx_ap_init_hwenc(cc, wlvif);
+ if (ret < 0)
+ return;
+
+ set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
+ }
+ } else {
+ if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
+ /* AP might be in ROC in case we have just
+ * sent auth reply. handle it.
+ */
+ if (test_bit(wlvif->role_id, cc->roc_map))
+ cc33xx_croc(cc, wlvif->role_id);
+
+ ret = cc33xx_cmd_role_stop_ap(cc, wlvif);
+ if (ret < 0)
+ return;
+
+ clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
+ clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
+ &wlvif->flags);
+ }
+ }
+ }
+
+ cc33xx_bss_erp_info_changed(cc, vif, bss_conf, changed);
+}
+
+static int cc33xx_set_bssid(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_bss_conf *bss_conf,
+ struct ieee80211_vif *vif,
+ u32 sta_rate_set)
+{
+ u32 rates;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "changed_bssid: %pM, aid: %d, bcn_int: %d, brates: 0x%x sta_rate_set: 0x%x, nontx: %d\n",
+ bss_conf->bssid, vif->cfg.aid, bss_conf->beacon_int,
+ bss_conf->basic_rates, sta_rate_set,
+ bss_conf->nontransmitted);
+
+ wlvif->beacon_int = bss_conf->beacon_int;
+ rates = bss_conf->basic_rates;
+ wlvif->basic_rate_set = cc33xx_tx_enabled_rates_get(cc, rates,
+ wlvif->band);
+ wlvif->basic_rate = cc33xx_tx_min_rate_get(wlvif->basic_rate_set);
+
+ if (sta_rate_set)
+ wlvif->rate_set = cc33xx_tx_enabled_rates_get(cc, sta_rate_set,
+ wlvif->band);
+
+ wlvif->nontransmitted = bss_conf->nontransmitted;
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "changed_mbssid: nonTxbssid: %d, idx: %d, max_ind: %d, trans_bssid: %pM, ema_ap: %d\n",
+ bss_conf->nontransmitted, bss_conf->bssid_index,
+ bss_conf->bssid_indicator, bss_conf->transmitter_bssid,
+ bss_conf->ema_ap);
+
+ if (bss_conf->nontransmitted) {
+ wlvif->bssid_index = bss_conf->bssid_index;
+ wlvif->bssid_indicator = bss_conf->bssid_indicator;
+ memcpy(wlvif->transmitter_bssid,
+ bss_conf->transmitter_bssid,
+ ETH_ALEN);
+ }
+
+ /* we only support sched_scan while not connected */
+ if (cc->sched_vif == wlvif)
+ cc33xx_scan_sched_scan_stop(cc, wlvif);
+
+ cc33xx_set_ssid(cc, wlvif);
+
+ set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
+
+ return 0;
+}
+
+static int cc33xx_clear_bssid(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret;
+
+ /* revert back to minimum rates for the current band */
+ cc33xx_set_band_rate(wlvif);
+ wlvif->basic_rate = cc33xx_tx_min_rate_get(wlvif->basic_rate_set);
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
+ test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags)) {
+ ret = cc33xx_cmd_role_stop_sta(cc, wlvif);
+ if (ret < 0)
+ return ret;
+ }
+
+ clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
+ return 0;
+}
+
+static void cc33xx_sta_set_he(struct cc33xx *cc, struct cc33xx_vif *wlvif, bool has_he)
+{
+ struct cc33xx_vif *wlvif_itr;
+ u8 he_count = 0;
+
+ wlvif->sta_has_he = has_he;
+
+ dev_info(cc->dev, "HE %s\n", str_enabled_disabled(has_he));
+
+ cc33xx_for_each_wlvif_sta(cc, wlvif_itr) {
+ /* check for all valid link id's */
+ if (wlvif_itr->role_id != 0xFF && wlvif_itr->sta_has_he)
+ he_count++;
+ }
+
+ /* There can't be two stations connected with HE supported links */
+ if (he_count > 1)
+ dev_err(cc->dev, "Both station interfaces has HE enabled!\n");
+}
+
+/* STA/IBSS mode changes */
+static void cc33xx_bss_info_changed_sta(struct cc33xx *cc,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *bss_conf,
+ u64 changed)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ bool do_join = false;
+ u32 sta_rate_set = 0;
+ int ret;
+ struct ieee80211_sta *sta = NULL;
+ bool sta_exists = false;
+ struct ieee80211_sta_ht_cap sta_ht_cap;
+ struct ieee80211_sta_he_cap sta_he_cap;
+
+ if (changed & BSS_CHANGED_IDLE)
+ cc33xx_sta_handle_idle(cc, wlvif, vif->cfg.idle);
+
+ if (changed & BSS_CHANGED_CQM)
+ wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
+
+ if (changed & (BSS_CHANGED_BSSID | BSS_CHANGED_HT | BSS_CHANGED_ASSOC)) {
+ rcu_read_lock();
+ sta = ieee80211_find_sta(vif, bss_conf->bssid);
+ if (sta) {
+ u8 *rx_mask = sta->deflink.ht_cap.mcs.rx_mask;
+
+ /* save the supp_rates of the ap */
+ sta_rate_set = sta->deflink.supp_rates[wlvif->band];
+ if (sta->deflink.ht_cap.ht_supported) {
+ sta_rate_set |=
+ (rx_mask[0] << HW_HT_RATES_OFFSET) |
+ (rx_mask[1] << HW_MIMO_RATES_OFFSET);
+ }
+ sta_ht_cap = sta->deflink.ht_cap;
+ sta_he_cap = sta->deflink.he_cap;
+ sta_exists = true;
+ }
+
+ rcu_read_unlock();
+ }
+
+ if (changed & BSS_CHANGED_BSSID) {
+ if (!is_zero_ether_addr(bss_conf->bssid)) {
+ ret = cc33xx_set_bssid(cc, wlvif,
+ bss_conf, vif, sta_rate_set);
+ if (ret < 0)
+ return;
+
+ /* Need to update the BSSID (for filtering etc) */
+ do_join = true;
+ } else {
+ ret = cc33xx_clear_bssid(cc, wlvif);
+ if (ret < 0)
+ return;
+ }
+ }
+
+ if ((changed & BSS_CHANGED_BEACON_INFO) && bss_conf->dtim_period) {
+ /* enable beacon filtering */
+ ret = cc33xx_acx_beacon_filter_opt(cc, wlvif, true);
+ if (ret < 0)
+ return;
+ }
+
+ ret = cc33xx_bss_erp_info_changed(cc, vif, bss_conf, changed);
+ if (ret < 0)
+ return;
+
+ if (do_join) {
+ ret = cc33xx_join(cc, wlvif);
+ if (ret < 0) {
+ dev_warn(cc->dev, "cmd join failed %d\n", ret);
+ return;
+ }
+ }
+
+ if (changed & BSS_CHANGED_ASSOC) {
+ if (vif->cfg.assoc) {
+ ret = cc33xx_set_assoc(cc, wlvif, bss_conf, sta, vif,
+ sta_rate_set);
+ if (ret < 0)
+ return;
+
+ if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
+ cc33xx_set_authorized(cc, wlvif);
+
+ if (sta)
+ cc33xx_sta_set_he(cc, wlvif, sta->deflink.he_cap.has_he);
+
+ } else {
+ cc33xx_unset_assoc(cc, wlvif);
+ }
+ }
+
+ if (changed & BSS_CHANGED_PS) {
+ if (vif->cfg.ps &&
+ test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
+ !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
+ int ps_mode;
+ char *ps_mode_str;
+
+ if (cc->conf.host_conf.conn.forced_ps) {
+ ps_mode = STATION_POWER_SAVE_MODE;
+ ps_mode_str = "forced";
+ } else {
+ ps_mode = STATION_AUTO_PS_MODE;
+ ps_mode_str = "auto";
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_PSM, "%s ps enabled\n", ps_mode_str);
+
+ ret = cc33xx_ps_set_mode(cc, wlvif, ps_mode);
+ if (ret < 0)
+ dev_warn(cc->dev, "enter %s ps failed %d\n",
+ ps_mode_str, ret);
+ } else if (!vif->cfg.ps && test_bit(WLVIF_FLAG_IN_PS,
+ &wlvif->flags)) {
+ cc33xx_debug(cc->dev, DEBUG_PSM, "auto ps disabled\n");
+
+ ret = cc33xx_ps_set_mode(cc, wlvif,
+ STATION_ACTIVE_MODE);
+ if (ret < 0)
+ dev_warn(cc->dev, "exit auto ps failed %d\n", ret);
+ }
+ }
+
+ /* Handle new association with HT. Do this after join. */
+ if (sta_exists) {
+ bool enabled = bss_conf->chanreq.oper.width !=
+ NL80211_CHAN_WIDTH_20_NOHT;
+ cc33xx_debug(cc->dev, DEBUG_CMD, "cc33xx_hw_set_peer_cap %x\n",
+ wlvif->rate_set);
+ ret = cc33xx_acx_set_peer_cap(cc, &sta_ht_cap, &sta_he_cap,
+ wlvif, enabled, wlvif->rate_set);
+ if (ret < 0) {
+ dev_warn(cc->dev, "Set ht cap failed %d\n", ret);
+ return;
+ }
+
+ if (enabled) {
+ ret = cc33xx_acx_set_ht_information(cc, wlvif,
+ bss_conf->ht_operation_mode,
+ bss_conf->he_oper.params,
+ bss_conf->he_oper.nss_set);
+ if (ret < 0) {
+ dev_warn(cc->dev, "Set ht information failed %d\n",
+ ret);
+ return;
+ }
+ }
+ }
+
+ if (changed & BSS_CHANGED_QOS) {
+ WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
+ wlvif->sta.qos = bss_conf->qos;
+ }
+}
+
+static void cc33xx_op_bss_info_changed(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *bss_conf,
+ u64 changed)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+ int ret, set_power;
+
+ /* make sure to cancel pending disconnections if our association
+ * state changed
+ */
+ if (!is_ap && (changed & BSS_CHANGED_ASSOC))
+ wiphy_delayed_work_cancel(cc->hw->wiphy,
+ &wlvif->connection_loss_work);
+
+ if (is_ap && (changed & BSS_CHANGED_BEACON_ENABLED) &&
+ !bss_conf->enable_beacon)
+ cc33xx_tx_flush(cc);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
+ return;
+
+ if ((changed & BSS_CHANGED_TXPOWER) && bss_conf->txpower != wlvif->power_level) {
+ /* bss_conf->txpower is initialized with a default value,
+ * meaning the power has not been set and should be ignored, use
+ * max value instead
+ */
+ set_power = (bss_conf->txpower == INT_MIN) ?
+ CC33XX_MAX_TXPWR : bss_conf->txpower;
+ ret = cc33xx_acx_tx_power(cc, wlvif, set_power);
+
+ if (ret < 0)
+ return;
+ }
+
+ if (is_ap)
+ cc33xx_bss_info_changed_ap(cc, vif, bss_conf, changed);
+ else
+ cc33xx_bss_info_changed_sta(cc, vif, bss_conf, changed);
+}
+
+static int cc33xx_op_add_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *ctx)
+{
+ struct cc33xx *cc = hw->priv;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 add chanctx %d (type %d)\n",
+ ieee80211_frequency_to_channel(ctx->def.chan->center_freq),
+ cfg80211_get_chandef_type(&ctx->def));
+ return 0;
+}
+
+static void cc33xx_op_remove_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *ctx)
+{
+ struct cc33xx *cc = hw->priv;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 remove chanctx %d (type %d)\n",
+ ieee80211_frequency_to_channel(ctx->def.chan->center_freq),
+ cfg80211_get_chandef_type(&ctx->def));
+}
+
+static void cc33xx_op_change_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *ctx,
+ u32 changed)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif;
+ int channel = ieee80211_frequency_to_channel(ctx->def.chan->center_freq);
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211,
+ "mac80211 change chanctx %d (type %d) changed 0x%x\n",
+ channel, cfg80211_get_chandef_type(&ctx->def), changed);
+
+ cc33xx_for_each_wlvif(cc, wlvif) {
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+
+ rcu_read_lock();
+ if (rcu_access_pointer(vif->bss_conf.chanctx_conf) != ctx) {
+ rcu_read_unlock();
+ continue;
+ }
+ rcu_read_unlock();
+ }
+}
+
+static int cc33xx_op_assign_vif_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *link_conf,
+ struct ieee80211_chanctx_conf *ctx)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int channel = ieee80211_frequency_to_channel(ctx->def.chan->center_freq);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return -EPERM;
+
+ if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
+ return -EPERM;
+
+ if (ctx->def.width > NL80211_CHAN_WIDTH_20)
+ return -EINVAL;
+
+ wlvif->band = ctx->def.chan->band;
+ wlvif->channel = channel;
+ wlvif->channel_type = cfg80211_get_chandef_type(&ctx->def);
+
+ /* update default rates according to the band */
+ cc33xx_set_band_rate(wlvif);
+
+ return 0;
+}
+
+static void cc33xx_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *link_conf,
+ struct ieee80211_chanctx_conf *ctx)
+{
+ struct cc33xx *cc = hw->priv;
+
+ cc33xx_tx_flush(cc);
+}
+
+static int cc33xx_switch_vif_chan(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct ieee80211_chanctx_conf *new_ctx)
+{
+ int channel = ieee80211_frequency_to_channel(new_ctx->def.chan->center_freq);
+
+ wlvif->band = new_ctx->def.chan->band;
+ wlvif->channel = channel;
+ wlvif->channel_type = cfg80211_get_chandef_type(&new_ctx->def);
+
+ return 0;
+}
+
+static int cc33xx_op_switch_vif_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_vif_chanctx_switch *vifs,
+ int n_vifs,
+ enum ieee80211_chanctx_switch_mode mode)
+{
+ struct cc33xx *cc = hw->priv;
+ int i, ret;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211,
+ "mac80211 switch chanctx n_vifs %d mode %d\n", n_vifs, mode);
+
+ for (i = 0; i < n_vifs; i++) {
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vifs[i].vif);
+
+ ret = cc33xx_switch_vif_chan(cc, wlvif, vifs[i].new_ctx);
+ if (ret)
+ break;
+ }
+
+ return 0;
+}
+
+static int cc33xx_op_conf_tx(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ unsigned int link_id, u16 queue,
+ const struct ieee80211_tx_queue_params *params)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ u8 ps_scheme;
+ int ret = 0;
+
+ if (cc33xx_is_p2p_mgmt(wlvif))
+ return 0;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 conf tx %d\n", queue);
+
+ if (params->uapsd)
+ ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
+ else
+ ps_scheme = CONF_PS_SCHEME_LEGACY;
+
+ if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+ return -EPERM;
+
+ ret = cc33xx_tx_param_cfg(cc, wlvif, cc33xx_tx_get_queue(queue),
+ params->cw_min, params->cw_max, params->aifs,
+ params->txop << 5, params->acm, ps_scheme,
+ params->mu_edca, params->mu_edca_param_rec.aifsn,
+ params->mu_edca_param_rec.ecw_min_max,
+ params->mu_edca_param_rec.mu_edca_timer);
+
+ return ret;
+}
+
+static int cc33xx_op_get_survey(struct ieee80211_hw *hw, int idx,
+ struct survey_info *survey)
+{
+ struct ieee80211_conf *conf = &hw->conf;
+
+ if (idx != 0)
+ return -ENOENT;
+
+ survey->channel = conf->chandef.chan;
+ survey->filled = 0;
+ return 0;
+}
+
+static int cc33xx_allocate_sta(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta)
+{
+ struct cc33xx_station *wl_sta;
+ int ret;
+
+ if (cc->active_sta_count >= CC33XX_MAX_AP_STATIONS) {
+ dev_warn(cc->dev, "could not allocate HLID - too much stations\n");
+ return -EBUSY;
+ }
+
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+
+ ret = cc33xx_set_link(cc, wlvif, wl_sta->hlid);
+
+ if (ret < 0) {
+ dev_warn(cc->dev, "could not allocate HLID - too many links\n");
+ return -EBUSY;
+ }
+
+ /* use the previous security seq, if this is a recovery/resume */
+ cc->links[wl_sta->hlid].total_freed_pkts = wl_sta->total_freed_pkts;
+
+ set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
+ memcpy(cc->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
+ cc->active_sta_count++;
+ return 0;
+}
+
+void cc33xx_free_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 hlid)
+{
+ if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
+ return;
+
+ clear_bit(hlid, wlvif->ap.sta_hlid_map);
+
+ cc33xx_free_wlsta_info(cc, wlvif, hlid, cc->links[hlid].addr);
+
+ cc33xx_clear_link(cc, wlvif, &hlid);
+ cc->active_sta_count--;
+}
+
+static int cc33xx_sta_add(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta)
+{
+ struct cc33xx_station *wl_sta;
+ int ret = 0;
+ u8 hlid;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 add sta %d\n", (int)sta->aid);
+
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+ ret = cc33xx_cmd_add_peer(cc, wlvif, sta, &hlid, 0);
+ if (ret < 0)
+ return ret;
+
+ wl_sta->hlid = hlid;
+ ret = cc33xx_allocate_sta(cc, wlvif, sta);
+
+ return ret;
+}
+
+static int cc33xx_sta_remove(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta)
+{
+ struct cc33xx_station *wl_sta;
+ int ret = 0, id;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 remove sta %d\n", (int)sta->aid);
+
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+ id = wl_sta->hlid;
+ if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
+ return -EINVAL;
+
+ ret = cc33xx_cmd_remove_peer(cc, wlvif, wl_sta->hlid);
+ if (ret < 0)
+ return ret;
+
+ cc33xx_free_sta(cc, wlvif, wl_sta->hlid);
+ return ret;
+}
+
+static void cc33xx_roc_if_possible(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ if (find_first_bit(cc->roc_map, CC33XX_MAX_ROLES) < CC33XX_MAX_ROLES)
+ return;
+
+ if (WARN_ON(wlvif->role_id == CC33XX_INVALID_ROLE_ID))
+ return;
+
+ cc33xx_roc(cc, wlvif, wlvif->role_id, wlvif->band, wlvif->channel);
+}
+
+/* The FW must be awake when the call takes place.
+ */
+void cc33xx_update_inconn_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cc33xx_station *wl_sta, bool in_conn)
+{
+ cc33xx_debug(cc->dev, DEBUG_CMD, "update_inconn_sta: in_conn=%d count=%d\n",
+ in_conn, wlvif->inconn_count);
+
+ if (!wl_sta)
+ return;
+
+ if (in_conn) {
+ if (WARN_ON(wl_sta->in_connection))
+ return;
+
+ if (!wlvif->inconn_count) {
+ cc33xx_roc_if_possible(cc, wlvif);
+ if (test_bit(wlvif->role_id, cc->roc_map)) {
+ unsigned long roc_cmplt_jiffies =
+ msecs_to_jiffies(ROC_PENDING_COMPLETE_TIMEOUT);
+
+ cc33xx_debug(cc->dev, DEBUG_AP, "delay queue roc_timeout_work\n");
+
+ wiphy_delayed_work_queue(cc->hw->wiphy,
+ &wlvif->roc_timeout_work,
+ roc_cmplt_jiffies);
+ }
+ }
+
+ wl_sta->in_connection = true;
+ wlvif->inconn_count++;
+ } else {
+ if (!wl_sta->in_connection)
+ return;
+
+ if (WARN_ON(!wlvif->inconn_count))
+ return;
+
+ wl_sta->in_connection = false;
+ wlvif->inconn_count--;
+
+ if (!wlvif->inconn_count &&
+ test_bit(wlvif->role_id, cc->roc_map)) {
+ cc33xx_croc(cc, wlvif->role_id);
+ /* remove timer for croc t/o */
+ cc33xx_debug(cc->dev, DEBUG_AP, "Cancel pending_roc timeout\n");
+ wiphy_delayed_work_cancel(cc->hw->wiphy,
+ &wlvif->roc_timeout_work);
+ }
+ }
+}
+
+static int cc33xx_update_sta_state(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ struct ieee80211_sta *sta,
+ enum ieee80211_sta_state old_state,
+ enum ieee80211_sta_state new_state)
+{
+ struct cc33xx_station *wl_sta;
+ bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
+ bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
+ int ret;
+
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+
+ /* Add station (AP mode) */
+ if (is_ap && old_state == IEEE80211_STA_NOTEXIST && new_state == IEEE80211_STA_NONE) {
+ ret = cc33xx_sta_add(cc, wlvif, sta);
+ if (ret)
+ return ret;
+
+ cc33xx_update_inconn_sta(cc, wlvif, wl_sta, true);
+ }
+
+ /* Remove station (AP mode) */
+ if (is_ap && old_state == IEEE80211_STA_NONE && new_state == IEEE80211_STA_NOTEXIST) {
+ /* must not fail */
+ cc33xx_sta_remove(cc, wlvif, sta);
+
+ cc33xx_update_inconn_sta(cc, wlvif, wl_sta, false);
+ }
+
+ /* Authorize station (AP mode) */
+ if (is_ap && new_state == IEEE80211_STA_AUTHORIZED) {
+ /* reconfigure peer */
+ ret = cc33xx_cmd_add_peer(cc, wlvif, sta, NULL, true);
+ if (ret < 0)
+ return ret;
+
+ cc33xx_update_inconn_sta(cc, wlvif, wl_sta, false);
+ }
+
+ /* Authorize station */
+ if (is_sta && new_state == IEEE80211_STA_AUTHORIZED) {
+ set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
+ ret = cc33xx_set_authorized(cc, wlvif);
+ if (ret)
+ return ret;
+ }
+
+ if (is_sta && old_state == IEEE80211_STA_AUTHORIZED && new_state == IEEE80211_STA_ASSOC) {
+ clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
+ clear_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags);
+ }
+
+ /* save seq number on disassoc (suspend) */
+ if (is_sta && old_state == IEEE80211_STA_ASSOC && new_state == IEEE80211_STA_AUTH) {
+ cc33xx_save_freed_pkts(cc, wlvif->sta.hlid, wl_sta);
+ wlvif->total_freed_pkts = 0;
+ }
+
+ /* restore seq number on assoc (resume) */
+ if (is_sta && old_state == IEEE80211_STA_AUTH && new_state == IEEE80211_STA_ASSOC)
+ wlvif->total_freed_pkts = wl_sta->total_freed_pkts;
+
+ /* clear ROCs on failure or authorization */
+ if (is_sta &&
+ (new_state == IEEE80211_STA_AUTHORIZED ||
+ new_state == IEEE80211_STA_NOTEXIST)) {
+ if (test_bit(wlvif->role_id, cc->roc_map))
+ cc33xx_croc(cc, wlvif->role_id);
+ }
+
+ if (is_sta && (old_state == IEEE80211_STA_NOTEXIST &&
+ new_state == IEEE80211_STA_NONE)) {
+ if (find_first_bit(cc->roc_map,
+ CC33XX_MAX_ROLES) >= CC33XX_MAX_ROLES) {
+ WARN_ON(wlvif->role_id == CC33XX_INVALID_ROLE_ID);
+ cc33xx_roc(cc, wlvif, wlvif->role_id,
+ wlvif->band, wlvif->channel);
+ }
+ }
+
+ return 0;
+}
+
+static int cc33xx_op_sta_state(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta,
+ enum ieee80211_sta_state old_state,
+ enum ieee80211_sta_state new_state)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 sta %d state=%d->%d\n",
+ sta->aid, old_state, new_state);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return 0;
+
+ ret = cc33xx_update_sta_state(cc, wlvif, sta, old_state, new_state);
+
+ if (new_state < old_state)
+ return 0;
+ return ret;
+}
+
+static int cc33xx_op_ampdu_action(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_ampdu_params *params)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+ u8 hlid, *ba_bitmap;
+ struct ieee80211_sta *sta = params->sta;
+ enum ieee80211_ampdu_mlme_action action = params->action;
+ u16 tid = params->tid;
+ u16 *ssn = ¶ms->ssn;
+
+ /* sanity check - the fields in FW are only 8bits wide */
+ if (WARN_ON(tid > 0xFF))
+ return -EOPNOTSUPP;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return 0;
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
+ hlid = wlvif->sta.hlid;
+ } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
+ struct cc33xx_station *wl_sta;
+
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+ hlid = wl_sta->hlid;
+ } else {
+ return -EINVAL;
+ }
+
+ if (hlid == CC33XX_INVALID_LINK_ID)
+ return 0;
+
+ if (WARN_ON(hlid >= CC33XX_MAX_LINKS))
+ return -EINVAL;
+
+ ba_bitmap = &cc->links[hlid].ba_bitmap;
+
+ switch (action) {
+ case IEEE80211_AMPDU_RX_START:
+ if (!wlvif->ba_support || !wlvif->ba_allowed) {
+ ret = -EOPNOTSUPP;
+ break;
+ }
+
+ if (cc->ba_rx_session_count >= CC33XX_RX_BA_MAX_SESSIONS) {
+ ret = -EBUSY;
+ dev_err(cc->dev, "exceeded max RX BA sessions\n");
+ break;
+ }
+
+ if (*ba_bitmap & BIT(tid)) {
+ ret = -EINVAL;
+ dev_err(cc->dev, "cannot enable RX BA session on active tid: %d\n",
+ tid);
+ break;
+ }
+
+ ret = cc33xx_acx_set_ba_receiver_session(cc, tid, *ssn,
+ true, hlid,
+ params->buf_size);
+
+ if (!ret) {
+ *ba_bitmap |= BIT(tid);
+ cc->ba_rx_session_count++;
+ }
+ break;
+
+ case IEEE80211_AMPDU_RX_STOP:
+ if (!(*ba_bitmap & BIT(tid))) {
+ /* this happens on reconfig - so only output a debug
+ * message for now, and don't fail the function.
+ */
+ cc33xx_debug(cc->dev, DEBUG_MAC80211,
+ "no active RX BA session on tid: %d\n", tid);
+ ret = 0;
+ break;
+ }
+
+ ret = cc33xx_acx_set_ba_receiver_session(cc, tid, 0,
+ false, hlid, 0);
+ if (!ret) {
+ *ba_bitmap &= ~BIT(tid);
+ cc->ba_rx_session_count--;
+ }
+ break;
+
+ /* The BA initiator session management in FW independently.
+ * Falling break here on purpose for all TX APDU commands.
+ */
+ case IEEE80211_AMPDU_TX_START:
+ case IEEE80211_AMPDU_TX_STOP_CONT:
+ case IEEE80211_AMPDU_TX_STOP_FLUSH:
+ case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
+ case IEEE80211_AMPDU_TX_OPERATIONAL:
+ ret = -EINVAL;
+ break;
+
+ default:
+ dev_err(cc->dev, "Incorrect ampdu action id=%x\n\n", action);
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+static int cc33xx_set_bitrate_mask(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ const struct cfg80211_bitrate_mask *mask)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct cc33xx *cc = hw->priv;
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x\n",
+ mask->control[NL80211_BAND_2GHZ].legacy,
+ mask->control[NL80211_BAND_5GHZ].legacy);
+
+ wlvif->bitrate_masks[0] = cc33xx_tx_enabled_rates_get(cc,
+ mask->control[0].legacy, 0);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return 0;
+
+ if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
+ !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
+ cc33xx_set_band_rate(wlvif);
+ wlvif->basic_rate = cc33xx_tx_min_rate_get(wlvif->basic_rate_set);
+ }
+
+ return 0;
+}
+
+static void cc33xx_op_channel_switch(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_channel_switch *ch_switch)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+
+ cc33xx_tx_flush(cc);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON)) {
+ if (cc->state == CC33XX_STATE_OFF &&
+ test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ ieee80211_chswitch_done(vif, false, 0);
+ return;
+ }
+
+ if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
+ unsigned long delay_usec;
+
+ ret = cc33xx_cmd_channel_switch(cc, wlvif, ch_switch);
+ if (ret)
+ return;
+
+ set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
+
+ /* indicate failure 5 seconds after channel switch time */
+ delay_usec = ieee80211_tu_to_usec(wlvif->beacon_int) *
+ ch_switch->count;
+ wiphy_delayed_work_queue(hw->wiphy, &wlvif->channel_switch_work,
+ usecs_to_jiffies(delay_usec) +
+ msecs_to_jiffies(5000));
+ }
+}
+
+static void cc33xx_op_channel_switch_beacon(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct cfg80211_chan_def *chandef)
+{
+ struct cc33xx *cc = hw->priv;
+
+ dev_err(cc->dev, "AP channel switch is not supported\n");
+}
+
+static void cc33xx_op_flush(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ u32 queues, bool drop)
+{
+ cc33xx_tx_flush(hw->priv);
+}
+
+static int cc33xx_op_remain_on_channel(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_channel *chan,
+ int duration,
+ enum ieee80211_roc_type type)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct cc33xx *cc = hw->priv;
+ int channel, active_roc, ret = 0;
+
+ channel = ieee80211_frequency_to_channel(chan->center_freq);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return -EINVAL;
+
+ /* return EBUSY if we can't ROC right now */
+ active_roc = find_first_bit(cc->roc_map, CC33XX_MAX_ROLES);
+ if (cc->roc_vif || active_roc < CC33XX_MAX_ROLES) {
+ dev_warn(cc->dev, "active roc on role %d\n", active_roc);
+ return -EBUSY;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_MAC80211,
+ "call cc33xx_start_dev, band = %d, channel = %d\n",
+ chan->band, channel);
+ ret = cc33xx_start_dev(cc, wlvif, chan->band, channel);
+ if (ret < 0)
+ return ret;
+
+ cc->roc_vif = vif;
+
+ wiphy_delayed_work_queue(hw->wiphy, &cc->roc_complete_work,
+ msecs_to_jiffies(duration));
+
+ return ret;
+}
+
+static int __cc33xx_roc_completed(struct cc33xx *cc)
+{
+ struct cc33xx_vif *wlvif;
+ int ret;
+
+ /* already completed */
+ if (unlikely(!cc->roc_vif))
+ return 0;
+
+ wlvif = cc33xx_vif_to_data(cc->roc_vif);
+
+ if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+ return -EBUSY;
+
+ ret = cc33xx_stop_dev(cc, wlvif);
+ if (ret < 0)
+ return ret;
+
+ cc->roc_vif = NULL;
+
+ return 0;
+}
+
+static int cc33xx_roc_completed(struct cc33xx *cc)
+{
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return -EBUSY;
+
+ return __cc33xx_roc_completed(cc);
+}
+
+static void cc33xx_roc_complete_work(struct wiphy *wiphy,
+ struct wiphy_work *work)
+
+{
+ struct cc33xx *cc;
+ int ret;
+
+ cc = container_of(work, struct cc33xx, roc_complete_work.work);
+
+ ret = cc33xx_roc_completed(cc);
+ if (!ret)
+ ieee80211_remain_on_channel_expired(cc->hw);
+}
+
+static int cc33xx_op_cancel_remain_on_channel(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx *cc = hw->priv;
+
+ cc33xx_tx_flush(cc);
+
+ wiphy_delayed_work_cancel(cc->hw->wiphy, &cc->roc_complete_work);
+ cc33xx_roc_completed(cc);
+
+ return 0;
+}
+
+static void cc33xx_op_sta_statistics(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta,
+ struct station_info *sinfo)
+{
+ struct cc33xx *cc = hw->priv;
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ s8 rssi_dbm;
+ int ret;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ ret = cc33xx_acx_average_rssi(cc, wlvif, &rssi_dbm);
+ if (ret < 0)
+ return;
+
+ sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
+ sinfo->signal = rssi_dbm;
+
+ ret = cc33xx_acx_get_tx_rate(cc, wlvif, sinfo);
+ if (ret < 0)
+ return;
+}
+
+static u32 cc33xx_op_get_expected_throughput(struct ieee80211_hw *hw,
+ struct ieee80211_sta *sta)
+{
+ struct cc33xx_station *wl_sta = (struct cc33xx_station *)sta->drv_priv;
+ struct cc33xx *cc = hw->priv;
+ u8 hlid = wl_sta->hlid;
+
+ /* return in units of Kbps */
+ return (cc->links[hlid].fw_rate_mbps * 1000);
+}
+
+static bool cc33xx_tx_frames_pending(struct ieee80211_hw *hw)
+{
+ struct cc33xx *cc = hw->priv;
+ bool ret;
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return false;
+
+ guard(mutex)(&cc->mutex);
+ /* packets are considered pending if in the TX queue or the FW */
+ ret = (cc33xx_tx_total_queue_count(cc) > 0) || (cc->tx_frames_cnt > 0);
+
+ return ret;
+}
+
+#ifdef CONFIG_PM
+
+static const struct wiphy_wowlan_support cc33xx_wowlan_support = {
+ .flags = WIPHY_WOWLAN_ANY,
+ .n_patterns = CC33XX_MAX_RX_FILTERS,
+ .pattern_min_len = 1,
+ .pattern_max_len = RX_FILTER_MAX_PATTERN_SIZE,
+};
+
+static void setup_wake_irq(struct cc33xx *cc)
+{
+ struct platform_device *pdev = cc->pdev;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+
+ struct resource *res;
+ int ret;
+
+ device_init_wakeup(cc->dev, true);
+
+ if (pdev_data->pwr_in_suspend)
+ cc->hw->wiphy->wowlan = &cc33xx_wowlan_support;
+
+ res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+ if (res) {
+ cc->wakeirq = res->start;
+ ret = dev_pm_set_dedicated_wake_irq(cc->dev, cc->wakeirq);
+ if (ret)
+ cc->wakeirq = -ENODEV;
+ } else {
+ cc->wakeirq = -ENODEV;
+ }
+
+ cc->keep_device_power = true;
+}
+#else
+
+static inline void setup_wake_irq(struct cc33xx *cc)
+{
+ cc->keep_device_power = true;
+}
+
+#endif /* CONFIG_PM */
+
+static const struct ieee80211_ops cc33xx_ops = {
+ .start = cc33xx_op_start,
+ .stop = cc33xx_op_stop,
+ .add_interface = cc33xx_op_add_interface,
+ .remove_interface = cc33xx_op_remove_interface,
+ .change_interface = cc33xx_op_change_interface,
+#ifdef CONFIG_PM
+ .suspend = cc33xx_op_suspend,
+ .resume = cc33xx_op_resume,
+#endif
+ .prepare_multicast = cc33xx_op_prepare_multicast,
+ .configure_filter = cc33xx_op_configure_filter,
+ .tx = cc33xx_op_tx,
+ .wake_tx_queue = cc33xx_handle_wake_tx_queue,
+ .set_key = cc33xx_op_set_key,
+ .hw_scan = cc33xx_op_hw_scan,
+ .cancel_hw_scan = cc33xx_op_cancel_hw_scan,
+ .sched_scan_start = cc33xx_op_sched_scan_start,
+ .sched_scan_stop = cc33xx_op_sched_scan_stop,
+ .bss_info_changed = cc33xx_op_bss_info_changed,
+ .set_frag_threshold = cc33xx_op_set_frag_threshold,
+ .set_rts_threshold = cc33xx_op_set_rts_threshold,
+ .conf_tx = cc33xx_op_conf_tx,
+ .get_survey = cc33xx_op_get_survey,
+ .sta_state = cc33xx_op_sta_state,
+ .ampdu_action = cc33xx_op_ampdu_action,
+ .tx_frames_pending = cc33xx_tx_frames_pending,
+ .set_bitrate_mask = cc33xx_set_bitrate_mask,
+ .set_default_unicast_key = cc33xx_op_set_default_key_idx,
+ .channel_switch = cc33xx_op_channel_switch,
+ .channel_switch_beacon = cc33xx_op_channel_switch_beacon,
+ .flush = cc33xx_op_flush,
+ .remain_on_channel = cc33xx_op_remain_on_channel,
+ .cancel_remain_on_channel = cc33xx_op_cancel_remain_on_channel,
+ .add_chanctx = cc33xx_op_add_chanctx,
+ .remove_chanctx = cc33xx_op_remove_chanctx,
+ .change_chanctx = cc33xx_op_change_chanctx,
+ .assign_vif_chanctx = cc33xx_op_assign_vif_chanctx,
+ .unassign_vif_chanctx = cc33xx_op_unassign_vif_chanctx,
+ .switch_vif_chanctx = cc33xx_op_switch_vif_chanctx,
+ .sta_statistics = cc33xx_op_sta_statistics,
+ .get_expected_throughput = cc33xx_op_get_expected_throughput,
+ CFG80211_TESTMODE_CMD(cc33xx_tm_cmd)
+};
+
+u8 cc33xx_rate_to_idx(u8 rate, enum nl80211_band band)
+{
+ if (WARN_ON(band > NL80211_BAND_5GHZ))
+ return 0;
+
+ if (unlikely(rate > CONF_HW_RATE_INDEX_MAX))
+ return CONF_HW_RXTX_RATE_UNSUPPORTED;
+
+ return cc33xx_band_rate_to_idx[band][rate];
+}
+
+static void cc33xx_derive_mac_addresses(struct cc33xx *cc)
+{
+ const u8 zero_mac[ETH_ALEN] = {0};
+ u8 base_addr[ETH_ALEN];
+ u8 bd_addr[ETH_ALEN];
+
+ if (!ether_addr_equal(zero_mac, cc->efuse_mac_address)) {
+ u8 oui_laa_bit = BIT(1);
+ u8 oui_multicast_bit = BIT(0);
+
+ cc33xx_debug(cc->dev, DEBUG_BOOT,
+ "MAC address derived from EFUSE\n");
+ ether_addr_copy(base_addr, cc->efuse_mac_address);
+
+ base_addr[0] &= ~oui_multicast_bit;
+
+ ether_addr_copy(cc->addresses[0].addr, base_addr);
+ ether_addr_copy(cc->addresses[1].addr, base_addr);
+ ether_addr_copy(cc->addresses[2].addr, base_addr);
+ ether_addr_copy(bd_addr, base_addr);
+
+ cc->addresses[1].addr[0] |= oui_laa_bit;
+ cc->addresses[2].addr[0] |= oui_laa_bit;
+
+ eth_addr_inc(cc->addresses[2].addr);
+ eth_addr_inc(bd_addr);
+ } else {
+ dev_warn(cc->dev, "No EFUSE data, using random locally administered address.\n");
+ eth_random_addr(base_addr);
+
+ ether_addr_copy(cc->addresses[0].addr, base_addr);
+ ether_addr_copy(cc->addresses[1].addr, base_addr);
+ ether_addr_copy(cc->addresses[2].addr, base_addr);
+ ether_addr_copy(bd_addr, base_addr);
+
+ eth_addr_inc(bd_addr);
+ eth_addr_inc(cc->addresses[1].addr);
+ eth_addr_inc(cc->addresses[1].addr);
+ eth_addr_inc(cc->addresses[2].addr);
+ eth_addr_inc(cc->addresses[2].addr);
+ eth_addr_inc(cc->addresses[2].addr);
+ }
+
+ cc->hw->wiphy->n_addresses = CC33XX_NUM_MAC_ADDRESSES;
+ cc->hw->wiphy->addresses = cc->addresses;
+
+ cc33xx_cmd_set_bd_addr(cc, bd_addr);
+}
+
+static int cc33xx_register_hw(struct cc33xx *cc)
+{
+ int ret;
+
+ if (cc->mac80211_registered)
+ return 0;
+
+ cc33xx_derive_mac_addresses(cc);
+
+ ret = ieee80211_register_hw(cc->hw);
+ if (ret < 0) {
+ dev_err(cc->dev, "unable to register mac80211 hw: %d\n", ret);
+ return ret;
+ }
+
+ cc->mac80211_registered = true;
+
+ return ret;
+}
+
+static void cc33xx_unregister_hw(struct cc33xx *cc)
+{
+ if (cc->plt)
+ cc33xx_plt_stop(cc);
+
+ ieee80211_unregister_hw(cc->hw);
+ cc->mac80211_registered = false;
+}
+
+static int cc33xx_init_ieee80211(struct cc33xx *cc)
+{
+ unsigned int i;
+
+ if (cc->conf.core.mixed_mode_support) {
+ static const u32 cipher_suites[] = {
+ WLAN_CIPHER_SUITE_CCMP,
+ WLAN_CIPHER_SUITE_AES_CMAC,
+ WLAN_CIPHER_SUITE_TKIP,
+ WLAN_CIPHER_SUITE_GCMP,
+ WLAN_CIPHER_SUITE_GCMP_256,
+ WLAN_CIPHER_SUITE_BIP_GMAC_128,
+ WLAN_CIPHER_SUITE_BIP_GMAC_256,
+ };
+ cc->hw->wiphy->cipher_suites = cipher_suites;
+ cc->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
+
+ } else {
+ static const u32 cipher_suites[] = {
+ WLAN_CIPHER_SUITE_CCMP,
+ WLAN_CIPHER_SUITE_AES_CMAC,
+ WLAN_CIPHER_SUITE_GCMP,
+ WLAN_CIPHER_SUITE_GCMP_256,
+ WLAN_CIPHER_SUITE_BIP_GMAC_128,
+ WLAN_CIPHER_SUITE_BIP_GMAC_256,
+ };
+ cc->hw->wiphy->cipher_suites = cipher_suites;
+ cc->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
+ }
+
+ /* The tx descriptor buffer */
+ cc->hw->extra_tx_headroom = CC33XX_TX_EXTRA_HEADROOM;
+
+ if (cc->quirks & CC33XX_QUIRK_TKIP_HEADER_SPACE)
+ cc->hw->extra_tx_headroom += CC33XX_EXTRA_SPACE_TKIP;
+
+ /* unit us */
+ /* FIXME: find a proper value */
+ cc->hw->max_listen_interval =
+ cc->conf.host_conf.conn.max_listen_interval;
+
+ ieee80211_hw_set(cc->hw, SUPPORT_FAST_XMIT);
+ ieee80211_hw_set(cc->hw, CHANCTX_STA_CSA);
+ ieee80211_hw_set(cc->hw, QUEUE_CONTROL);
+ ieee80211_hw_set(cc->hw, TX_AMPDU_SETUP_IN_HW);
+ ieee80211_hw_set(cc->hw, AMPDU_AGGREGATION);
+ ieee80211_hw_set(cc->hw, AP_LINK_PS);
+ ieee80211_hw_set(cc->hw, SPECTRUM_MGMT);
+ ieee80211_hw_set(cc->hw, REPORTS_TX_ACK_STATUS);
+ ieee80211_hw_set(cc->hw, CONNECTION_MONITOR);
+ ieee80211_hw_set(cc->hw, HAS_RATE_CONTROL);
+ ieee80211_hw_set(cc->hw, SUPPORTS_DYNAMIC_PS);
+ ieee80211_hw_set(cc->hw, SIGNAL_DBM);
+ ieee80211_hw_set(cc->hw, SUPPORTS_PS);
+ ieee80211_hw_set(cc->hw, SUPPORTS_TX_FRAG);
+ ieee80211_hw_set(cc->hw, SUPPORTS_MULTI_BSSID);
+ ieee80211_hw_set(cc->hw, SUPPORTS_AMSDU_IN_AMPDU);
+
+ cc->hw->wiphy->interface_modes = cc33xx_wiphy_interface_modes();
+
+ cc->hw->wiphy->max_scan_ssids = 1;
+ cc->hw->wiphy->max_sched_scan_ssids = 16;
+ cc->hw->wiphy->max_match_sets = 16;
+ /* Maximum length of elements in scanning probe request templates
+ * should be the maximum length possible for a template, without
+ * the IEEE80211 header of the template
+ */
+ cc->hw->wiphy->max_scan_ie_len = CC33XX_CMD_TEMPL_MAX_SIZE -
+ sizeof(struct ieee80211_header);
+
+ cc->hw->wiphy->max_sched_scan_reqs = 1;
+ cc->hw->wiphy->max_sched_scan_ie_len = CC33XX_CMD_TEMPL_MAX_SIZE -
+ sizeof(struct ieee80211_header);
+
+ cc->hw->wiphy->max_remain_on_channel_duration = 30000;
+
+ cc->hw->wiphy->features |= NL80211_FEATURE_AP_SCAN;
+
+ /* We keep local copies of the band structs because we need to
+ * modify them on a per-device basis.
+ */
+ memcpy(&cc->bands[NL80211_BAND_2GHZ], &cc33xx_band_2ghz,
+ sizeof(cc33xx_band_2ghz));
+ memcpy(&cc->bands[NL80211_BAND_2GHZ].ht_cap,
+ &cc->ht_cap[NL80211_BAND_2GHZ],
+ sizeof(*cc->ht_cap));
+
+ memcpy(&cc->bands[NL80211_BAND_5GHZ], &cc33xx_band_5ghz,
+ sizeof(cc33xx_band_5ghz));
+ memcpy(&cc->bands[NL80211_BAND_5GHZ].ht_cap,
+ &cc->ht_cap[NL80211_BAND_5GHZ],
+ sizeof(*cc->ht_cap));
+
+ /* clear channel flags from the previous usage
+ * and restore max_power & max_antenna_gain values.
+ */
+ for (i = 0; i < ARRAY_SIZE(cc33xx_channels); i++) {
+ cc->bands[NL80211_BAND_2GHZ].channels[i].flags = 0;
+ cc->bands[NL80211_BAND_2GHZ].channels[i].max_power = CC33XX_MAX_TXPWR;
+ cc->bands[NL80211_BAND_2GHZ].channels[i].max_antenna_gain = 0;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(cc33xx_channels_5ghz); i++) {
+ cc->bands[NL80211_BAND_5GHZ].channels[i].flags = 0;
+ cc->bands[NL80211_BAND_5GHZ].channels[i].max_power = CC33XX_MAX_TXPWR;
+ cc->bands[NL80211_BAND_5GHZ].channels[i].max_antenna_gain = 0;
+ }
+
+ /* Enable/Disable He based on conf file params */
+ if (!cc->conf.mac.he_enable) {
+ cc->bands[NL80211_BAND_2GHZ].iftype_data = NULL;
+ cc->bands[NL80211_BAND_2GHZ].n_iftype_data = 0;
+
+ cc->bands[NL80211_BAND_5GHZ].iftype_data = NULL;
+ cc->bands[NL80211_BAND_5GHZ].n_iftype_data = 0;
+ }
+
+ ieee80211_set_sband_iftype_data(&cc->bands[NL80211_BAND_2GHZ], iftype_data_2ghz);
+ ieee80211_set_sband_iftype_data(&cc->bands[NL80211_BAND_5GHZ], iftype_data_5ghz);
+
+ cc->hw->wiphy->bands[NL80211_BAND_2GHZ] =
+ &cc->bands[NL80211_BAND_2GHZ];
+
+ if (!cc->disable_5g && cc->conf.core.enable_5ghz)
+ cc->hw->wiphy->bands[NL80211_BAND_5GHZ] =
+ &cc->bands[NL80211_BAND_5GHZ];
+
+ /* allow 4 queues per mac address we support +
+ * 1 cab queue per mac + one global offchannel Tx queue
+ */
+ cc->hw->queues = (NUM_TX_QUEUES + 1) * CC33XX_NUM_MAC_ADDRESSES + 1;
+
+ /* the last queue is the offchannel queue */
+ cc->hw->offchannel_tx_hw_queue = cc->hw->queues - 1;
+ cc->hw->max_rates = 1;
+
+ /* allowed interface combinations */
+ cc->hw->wiphy->iface_combinations = cc33xx_iface_combinations;
+ cc->hw->wiphy->n_iface_combinations = ARRAY_SIZE(cc33xx_iface_combinations);
+
+ SET_IEEE80211_DEV(cc->hw, cc->dev);
+
+ cc->hw->sta_data_size = sizeof(struct cc33xx_station);
+ cc->hw->vif_data_size = sizeof(struct cc33xx_vif);
+
+ cc->hw->max_rx_aggregation_subframes = cc->conf.host_conf.ht.rx_ba_win_size;
+
+ /* For all ps schemes don't use UAPSD, except for UAPSD scheme
+ * As these are the currently supportedd PS schemes, use the default
+ * legacy otherwise
+ */
+ if (cc->conf.mac.ps_scheme == PS_SCHEME_UPSD_TRIGGER) {
+ cc->hw->uapsd_queues = IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK;
+ } else if ((cc->conf.mac.ps_scheme != PS_SCHEME_LEGACY) &&
+ (cc->conf.mac.ps_scheme != PS_SCHEME_NOPSPOLL)) {
+ cc->hw->uapsd_queues = 0;
+ cc->conf.mac.ps_scheme = PS_SCHEME_LEGACY;
+ } else {
+ cc->hw->uapsd_queues = 0;
+ }
+
+ return 0;
+}
+
+static struct ieee80211_hw *cc33xx_alloc_hw(void)
+{
+ struct ieee80211_hw *hw;
+ struct cc33xx *cc;
+ int i, j;
+ unsigned int order;
+
+ hw = ieee80211_alloc_hw(sizeof(*cc), &cc33xx_ops);
+ if (!hw)
+ return NULL;
+
+ cc = hw->priv;
+ memset(cc, 0, sizeof(*cc));
+
+ INIT_LIST_HEAD(&cc->wlvif_list);
+
+ cc->hw = hw;
+
+ /* cc->num_links is not configured yet, so just use CC33XX_MAX_LINKS.
+ * we don't allocate any additional resource here, so that's fine.
+ */
+ for (j = 0; j < CC33XX_MAX_LINKS; j++)
+ skb_queue_head_init(&cc->links[j].tx_pending);
+
+ skb_queue_head_init(&cc->deferred_rx_queue);
+ skb_queue_head_init(&cc->deferred_tx_queue);
+
+ init_llist_head(&cc->event_list);
+
+ INIT_WORK(&cc->netstack_work, cc33xx_netstack_work);
+ INIT_WORK(&cc->tx_work, cc33xx_tx_work);
+ INIT_WORK(&cc->recovery_work, cc33xx_recovery_work);
+ INIT_WORK(&cc->irq_deferred_work, irq_deferred_work);
+ wiphy_delayed_work_init(&cc->scan_complete_work, cc33xx_scan_complete_work);
+ wiphy_delayed_work_init(&cc->roc_complete_work, cc33xx_roc_complete_work);
+
+ cc->freezable_netstack_wq = create_freezable_workqueue("cc33xx_netstack_wq");
+ if (!cc->freezable_netstack_wq)
+ goto err_hw_alloc;
+
+ cc->freezable_wq = alloc_workqueue("cc33xx_wq", __WQ_LEGACY |
+ WQ_FREEZABLE | WQ_UNBOUND | WQ_MEM_RECLAIM |
+ WQ_HIGHPRI, 1);
+
+ if (!cc->freezable_wq)
+ goto err_ns_wq;
+
+ cc->rx_counter = 0;
+ cc->flags = 0;
+ cc->sleep_auth = CC33XX_PSM_ILLEGAL;
+
+ cc->quirks = 0;
+ cc->active_sta_count = 0;
+ cc->active_link_count = 0;
+
+ /* The system link is always allocated */
+ __set_bit(CC33XX_SYSTEM_HLID, cc->links_map);
+
+ memset(cc->tx_frames_map, 0, sizeof(cc->tx_frames_map));
+ for (i = 0; i < CC33XX_NUM_TX_DESCRIPTORS; i++)
+ cc->tx_frames[i] = NULL;
+
+ spin_lock_init(&cc->cc_lock);
+
+ cc->state = CC33XX_STATE_OFF;
+ mutex_init(&cc->mutex);
+ mutex_init(&cc->cmd_lock);
+
+ order = get_order(CC33XX_AGGR_BUFFER_SIZE);
+ cc->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
+ if (!cc->aggr_buf)
+ goto err_all_wq;
+
+ cc->aggr_buf_size = CC33XX_AGGR_BUFFER_SIZE;
+
+ cc->core_status = kzalloc_obj(*cc->core_status);
+ if (!cc->core_status)
+ goto err_aggr;
+
+ return hw;
+
+err_aggr:
+ free_pages((unsigned long)cc->aggr_buf, order);
+
+err_all_wq:
+ destroy_workqueue(cc->freezable_wq);
+
+err_ns_wq:
+ destroy_workqueue(cc->freezable_netstack_wq);
+
+err_hw_alloc:
+ ieee80211_free_hw(cc->hw);
+
+ return NULL;
+}
+
+static int cc33xx_free_hw(struct cc33xx *cc)
+{
+ kfree(cc->core_status);
+ free_pages((unsigned long)cc->aggr_buf, get_order(cc->aggr_buf_size));
+
+ destroy_workqueue(cc->freezable_wq);
+ destroy_workqueue(cc->freezable_netstack_wq);
+ flush_deferred_event_list(cc);
+
+ ieee80211_free_hw(cc->hw);
+
+ return 0;
+}
+
+static int cc33xx_identify_chip(struct cc33xx *cc)
+{
+ cc->quirks |= CC33XX_QUIRK_RX_BLOCKSIZE_ALIGN |
+ CC33XX_QUIRK_TX_BLOCKSIZE_ALIGN |
+ CC33XX_QUIRK_NO_SCHED_SCAN_WHILE_CONN |
+ CC33XX_QUIRK_TX_PAD_LAST_FRAME |
+ CC33XX_QUIRK_DUAL_PROBE_TMPL;
+
+ if (cc->if_ops->get_max_transaction_len)
+ cc->max_transaction_len =
+ cc->if_ops->get_max_transaction_len(cc->dev);
+ else
+ cc->max_transaction_len = 0;
+
+ return 0;
+}
+
+static int read_version_info(struct cc33xx *cc)
+{
+ int ret;
+
+ ret = cc33xx_acx_init_get_fw_versions(cc);
+ if (ret < 0) {
+ dev_err(cc->dev, "Get FW version FAILED!\n");
+ return ret;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_BOOT, "Wireless firmware version %u.%u.%u.%u\n",
+ cc->fw_ver.major_version,
+ cc->fw_ver.minor_version,
+ cc->fw_ver.api_version,
+ cc->fw_ver.build_version);
+
+ cc33xx_debug(cc->dev, DEBUG_BOOT, "Wireless PHY version %u.%u.%u.%u.%u.%u\n",
+ cc->fw_ver.phy_version[5],
+ cc->fw_ver.phy_version[4],
+ cc->fw_ver.phy_version[3],
+ cc->fw_ver.phy_version[2],
+ cc->fw_ver.phy_version[1],
+ cc->fw_ver.phy_version[0]);
+
+ return 0;
+}
+
+static int cc33xx_init(struct cc33xx *cc)
+{
+ struct platform_device *pdev = cc->pdev;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+ int ret;
+
+ ret = cc33xx_setup(cc);
+ if (ret < 0)
+ return ret;
+
+ BUILD_BUG_ON(CC33XX_NUM_TX_DESCRIPTORS > CC33XX_MAX_TX_DESCRIPTORS);
+
+ /* adjust some runtime configuration parameters */
+ cc33xx_adjust_conf(cc);
+
+ cc->if_ops = pdev_data->if_ops;
+ cc->if_ops->set_irq_handler(cc->dev, irq_wrapper);
+
+ cc33xx_power_off(cc);
+
+ setup_wake_irq(cc);
+
+ ret = cc33xx_init_fw(cc);
+ if (ret < 0) {
+ dev_err(cc->dev, "FW download failed\n");
+ cc33xx_power_off(cc);
+ goto out_irq;
+ }
+
+ ret = cc33xx_identify_chip(cc);
+ if (ret < 0)
+ goto out_irq;
+
+ ret = read_version_info(cc);
+ if (ret < 0)
+ goto out_irq;
+
+ ret = cc33xx_init_ieee80211(cc);
+ if (ret)
+ goto out_irq;
+
+ ret = cc33xx_register_hw(cc);
+ if (ret)
+ goto out_irq;
+
+ cc->initialized = true;
+
+ cc33xx_debug(cc->dev, DEBUG_CC33XX, "%s complete\n", __func__);
+ return 0;
+
+out_irq:
+ if (cc->wakeirq >= 0)
+ dev_pm_clear_wake_irq(cc->dev);
+ device_init_wakeup(cc->dev, false);
+
+ return ret;
+}
+
+static int cc33xx_load_ini_bin_file(struct device *dev,
+ struct cc33xx_conf_file *conf,
+ const char *file)
+{
+ struct cc33xx_conf_file *conf_file;
+ const struct firmware *fw;
+ int ret;
+
+ ret = request_firmware(&fw, file, dev);
+ if (ret < 0) {
+ dev_err(dev, "could not get configuration binary %s: %d\n",
+ file, ret);
+ return ret;
+ }
+
+ if (fw->size != CC33X_CONF_SIZE) {
+ dev_err(dev, "%s configuration binary size is wrong, expected %zu got %zu\n",
+ file, CC33X_CONF_SIZE,
+ fw->size);
+ ret = -EINVAL;
+ goto out_release;
+ }
+
+ conf_file = (struct cc33xx_conf_file *)fw->data;
+
+ if (conf_file->header.magic != cpu_to_le32(CC33XX_CONF_MAGIC)) {
+ dev_err(dev, "conf file magic number mismatch, expected 0x%0x got 0x%0x\n",
+ CC33XX_CONF_MAGIC, conf_file->header.magic);
+ ret = -EINVAL;
+ goto out_release;
+ }
+
+ memcpy(conf, conf_file, sizeof(*conf));
+
+out_release:
+ release_firmware(fw);
+ return ret;
+}
+
+static int cc33xx_ini_bin_init(struct cc33xx *cc, struct device *dev)
+{
+ struct platform_device *pdev = cc->pdev;
+ struct cc33xx_platdev_data *pdata = dev_get_platdata(&pdev->dev);
+
+ if (cc33xx_load_ini_bin_file(dev, &cc->conf,
+ pdata->family->cfg_name) < 0)
+ dev_warn(cc->dev, "falling back to default config\n");
+
+ return 0;
+}
+
+static int cc33xx_setup(struct cc33xx *cc)
+{
+ int ret;
+
+ BUILD_BUG_ON(CC33XX_MAX_AP_STATIONS > CC33XX_MAX_LINKS);
+
+ ret = cc33xx_ini_bin_init(cc, cc->dev);
+ if (ret < 0)
+ return ret;
+
+ if (cc->conf.host_conf.ht.mode == HT_MODE_DEFAULT) {
+ cc33xx_set_ht_cap(cc, NL80211_BAND_2GHZ,
+ &cc33xx_siso40_ht_cap_2ghz);
+
+ /* 5Ghz is always wide */
+ cc33xx_set_ht_cap(cc, NL80211_BAND_5GHZ,
+ &cc33xx_siso40_ht_cap_5ghz);
+ } else if (cc->conf.host_conf.ht.mode == HT_MODE_WIDE) {
+ cc33xx_set_ht_cap(cc, NL80211_BAND_2GHZ,
+ &cc33xx_siso40_ht_cap_2ghz);
+ cc33xx_set_ht_cap(cc, NL80211_BAND_5GHZ,
+ &cc33xx_siso40_ht_cap_5ghz);
+ } else if (cc->conf.host_conf.ht.mode == HT_MODE_SISO20) {
+ cc33xx_set_ht_cap(cc, NL80211_BAND_2GHZ, &cc33xx_siso20_ht_cap);
+ cc33xx_set_ht_cap(cc, NL80211_BAND_5GHZ, &cc33xx_siso20_ht_cap);
+ }
+
+ cc->event_mask = BSS_LOSS_EVENT_ID | SCAN_COMPLETE_EVENT_ID |
+ RADAR_DETECTED_EVENT_ID | RSSI_SNR_TRIGGER_0_EVENT_ID |
+ PERIODIC_SCAN_COMPLETE_EVENT_ID |
+ PERIODIC_SCAN_REPORT_EVENT_ID | DUMMY_PACKET_EVENT_ID |
+ PEER_REMOVE_COMPLETE_EVENT_ID |
+ BA_SESSION_RX_CONSTRAINT_EVENT_ID |
+ REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
+ CHANNEL_SWITCH_COMPLETE_EVENT_ID |
+ DFS_CHANNELS_CONFIG_COMPLETE_EVENT |
+ SMART_CONFIG_SYNC_EVENT_ID | INACTIVE_STA_EVENT_ID |
+ SMART_CONFIG_DECODE_EVENT_ID | TIME_SYNC_EVENT_ID |
+ FW_LOGGER_INDICATION | RX_BA_WIN_SIZE_CHANGE_EVENT_ID;
+
+ cc->ap_event_mask = MAX_TX_FAILURE_EVENT_ID;
+
+ return 0;
+}
+
+static int cc33xx_probe(struct platform_device *pdev)
+{
+ struct cc33xx *cc;
+ struct ieee80211_hw *hw;
+ struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
+ int ret;
+
+ if (!pdev_data) {
+ dev_err(&pdev->dev, "can't access platform data\n");
+ return -EINVAL;
+ }
+
+ hw = cc33xx_alloc_hw();
+ if (!hw) {
+ dev_err(&pdev->dev, "can't allocate hw\n");
+ return -ENOMEM;
+ }
+
+ cc = hw->priv;
+ cc->dev = &pdev->dev;
+ cc->pdev = pdev;
+ platform_set_drvdata(pdev, cc);
+
+ ret = cc33xx_init(cc);
+ if (ret < 0) {
+ dev_err(cc->dev, "Init failed %d\n", ret);
+ cc33xx_free_hw(cc);
+ }
+
+ return ret;
+}
+
+static void cc33xx_remove(struct platform_device *pdev)
+{
+ struct cc33xx *cc = platform_get_drvdata(pdev);
+
+ set_bit(CC33XX_FLAG_DRIVER_REMOVED, &cc->flags);
+
+ cc->pdev->dev.driver->pm = NULL;
+
+ if (!cc->initialized)
+ goto out;
+
+ if (cc->wakeirq >= 0) {
+ dev_pm_clear_wake_irq(cc->dev);
+ cc->wakeirq = -ENODEV;
+ }
+
+ device_init_wakeup(cc->dev, false);
+ cc33xx_unregister_hw(cc);
+ cc33xx_turn_off(cc);
+
+out:
+ cc33xx_free_hw(cc);
+}
+
+static const struct platform_device_id cc33xx_id_table[] = {
+ { "cc33xx", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(platform, cc33xx_id_table);
+
+static struct platform_driver cc33xx_driver = {
+ .probe = cc33xx_probe,
+ .remove = cc33xx_remove,
+ .id_table = cc33xx_id_table,
+ .driver = {
+ .name = "cc33xx",
+ }
+};
+
+module_platform_driver(cc33xx_driver);
+
+module_param_named(debug_level, cc33xx_debug_level, uint, 0600);
+MODULE_PARM_DESC(debug_level, "cc33xx debugging level");
+
+module_param(no_recovery, int, 0600);
+MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck.");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Texas Instruments CC33xx WLAN driver");
+MODULE_AUTHOR("Michael Nemanov <michael.nemanov@ti.com>");
+MODULE_AUTHOR("Sabeeh Khan <sabeeh-khan@ti.com>");
+
+MODULE_FIRMWARE(SECOND_LOADER_NAME);
+MODULE_FIRMWARE(FW_NAME);
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (8 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 09/17] wifi: cc33xx: Add main.c Ramesh Ramalingam
@ 2026-12-03 7:08 ` Ramesh Ramalingam
2026-12-03 7:33 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
` (6 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:08 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
Code that handles parsing raw Rx data buffer from HW and, splitting
it in to SKBs and handing them to MAC80211.
Rx handling starts at cc33xx_rx. Full SKBs are stored at
cc->deferred_rx_queue from where they are handed to MAC80211 by calling
cc->netstack_work (cc33xx_netstack_work @ main.c). This allows
calling ieee80211_rx_ni while new data is being read from HW.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/rx.c | 385 ++++++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/rx.h | 86 +++++++
2 files changed, 471 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/rx.c
create mode 100644 drivers/net/wireless/ti/cc33xx/rx.h
diff --git a/drivers/net/wireless/ti/cc33xx/rx.c b/drivers/net/wireless/ti/cc33xx/rx.c
new file mode 100644
index 000000000000..81e16749ed0b
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/rx.c
@@ -0,0 +1,385 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "acx.h"
+#include "rx.h"
+#include "tx.h"
+#include "io.h"
+
+#define RSSI_LEVEL_BITMASK 0x7F
+#define ANT_DIVERSITY_BITMASK BIT(7)
+#define ANT_DIVERSITY_SHIFT 7
+
+/* Construct the rx status structure for upper layers */
+static void cc33xx_rx_status(struct cc33xx *cc,
+ struct cc33xx_rx_descriptor *desc,
+ struct ieee80211_rx_status *status,
+ u8 beacon, u8 probe_rsp)
+{
+ u8 rate_idx;
+
+ memset(status, 0, sizeof(struct ieee80211_rx_status));
+
+ if ((desc->flags & CC33XX_RX_DESC_BAND_MASK) == CC33XX_RX_DESC_BAND_BG)
+ status->band = NL80211_BAND_2GHZ;
+ else if ((desc->flags & CC33XX_RX_DESC_BAND_MASK) == CC33XX_RX_DESC_BAND_J)
+ status->band = NL80211_BAND_2GHZ;
+ else
+ status->band = NL80211_BAND_5GHZ;
+
+ rate_idx = cc33xx_rate_to_idx(desc->rate, status->band);
+ if (rate_idx == CONF_HW_RXTX_RATE_UNSUPPORTED)
+ dev_err(cc->dev, "Invalid RX rate from HW: %d\n", desc->rate);
+
+ status->rate_idx = rate_idx;
+
+ if (desc->frame_format == CC33XX_VHT)
+ status->encoding = RX_ENC_VHT;
+ else if ((desc->frame_format == CC33XX_HT_MF) ||
+ (desc->frame_format == CC33XX_HT_GF))
+ status->encoding = RX_ENC_HT;
+ else if ((desc->frame_format == CC33XX_B_SHORT) ||
+ (desc->frame_format == CC33XX_B_LONG) ||
+ (desc->frame_format == CC33XX_LEGACY_OFDM))
+ status->encoding = RX_ENC_LEGACY;
+ else
+ status->encoding = RX_ENC_HE;
+
+ /* Read the signal level and antenna diversity indication.
+ * The msb in the signal level is always set as it is a
+ * negative number.
+ * The antenna indication is the msb of the rssi.
+ */
+ status->signal = ((desc->rssi & RSSI_LEVEL_BITMASK) | BIT(7));
+ status->antenna = ((desc->rssi & ANT_DIVERSITY_BITMASK) >> ANT_DIVERSITY_SHIFT);
+ status->freq = ieee80211_channel_to_frequency(desc->channel,
+ status->band);
+
+ if (desc->flags & CC33XX_RX_DESC_ENCRYPT_MASK) {
+ u8 desc_err_code = desc->status & CC33XX_RX_DESC_STATUS_MASK;
+
+ /* Frame is sent to driver with the IV (for PN replay check)
+ * but without the MIC
+ */
+ status->flag |= RX_FLAG_MMIC_STRIPPED |
+ RX_FLAG_DECRYPTED | RX_FLAG_MIC_STRIPPED;
+
+ if (unlikely(desc_err_code & CC33XX_RX_DESC_MIC_FAIL)) {
+ status->flag |= RX_FLAG_MMIC_ERROR;
+ dev_warn(cc->dev, "Michael MIC error. Desc: 0x%x\n",
+ desc_err_code);
+ }
+ }
+
+ if (beacon || probe_rsp)
+ status->boottime_ns = ktime_get_boottime_ns();
+
+ status->nss = 1;
+}
+
+/* Copy part\ all of the descriptor. Allocate skb, or drop corrupted packet
+ */
+static int cc33xx_rx_get_packet_descriptor(struct cc33xx *cc, u8 *raw_buffer_ptr,
+ u16 *raw_buffer_len)
+{
+ u16 missing_desc_bytes;
+ u16 available_desc_bytes;
+ u16 pkt_data_len;
+ struct sk_buff *skb;
+ u16 prev_buffer_len = *raw_buffer_len;
+
+ missing_desc_bytes = sizeof(struct cc33xx_rx_descriptor);
+ missing_desc_bytes -= cc->partial_rx.handled_bytes;
+ available_desc_bytes = min(*raw_buffer_len, missing_desc_bytes);
+ memcpy(((u8 *)(&cc->partial_rx.desc)) + cc->partial_rx.handled_bytes,
+ raw_buffer_ptr, available_desc_bytes);
+
+ /* If descriptor was not completed */
+ if (available_desc_bytes != missing_desc_bytes) {
+ cc->partial_rx.handled_bytes += *raw_buffer_len;
+ cc->partial_rx.status = CURR_RX_DESC;
+ *raw_buffer_len = 0;
+ goto out;
+ } else {
+ cc->partial_rx.handled_bytes += available_desc_bytes;
+ *raw_buffer_len -= available_desc_bytes;
+ }
+
+ /* Descriptor was fully copied */
+ pkt_data_len = cc->partial_rx.original_bytes;
+ pkt_data_len -= sizeof(struct cc33xx_rx_descriptor);
+
+ if (unlikely(cc->partial_rx.desc.status & CC33XX_RX_DESC_DECRYPT_FAIL)) {
+ dev_warn(cc->dev, "corrupted packet in RX: status: 0x%x len: %d\n",
+ cc->partial_rx.desc.status & CC33XX_RX_DESC_STATUS_MASK,
+ pkt_data_len);
+
+ /* If frame can be fully dropped */
+ if (pkt_data_len <= *raw_buffer_len) {
+ *raw_buffer_len -= pkt_data_len;
+ cc->partial_rx.status = CURR_RX_START;
+ } else {
+ cc->partial_rx.handled_bytes += *raw_buffer_len;
+ cc->partial_rx.status = CURR_RX_DROP;
+ *raw_buffer_len = 0;
+ }
+ goto out;
+ }
+
+ skb = __dev_alloc_skb(pkt_data_len, GFP_KERNEL);
+ if (!skb) {
+ /* If frame can be fully dropped */
+ if (pkt_data_len <= *raw_buffer_len) {
+ *raw_buffer_len -= pkt_data_len;
+ cc->partial_rx.status = CURR_RX_START;
+ } else {
+ /* Dropped partial frame */
+ cc->partial_rx.handled_bytes += *raw_buffer_len;
+ cc->partial_rx.status = CURR_RX_DROP;
+ *raw_buffer_len = 0;
+ }
+ goto out;
+ }
+
+ cc->partial_rx.skb = skb;
+ cc->partial_rx.status = CURR_RX_DATA;
+
+out:
+ /* Function return the amount of consumed bytes */
+ return (prev_buffer_len - *raw_buffer_len);
+}
+
+/* Copy part or all of the packet's data. push skb to queue if possible */
+static int cc33xx_rx_get_packet_data(struct cc33xx *cc, u8 *raw_buffer_ptr,
+ u16 *raw_buffer_len)
+{
+ u16 missing_data_bytes;
+ u16 available_data_bytes;
+ u32 defer_count;
+ enum cc33xx_rx_buf_align rx_align;
+ u16 extra_bytes;
+ struct ieee80211_hdr *hdr;
+ u8 beacon = 0;
+ u8 is_probe_resp = 0;
+ u16 seq_num;
+ u16 prev_buffer_len = *raw_buffer_len;
+
+ missing_data_bytes = cc->partial_rx.original_bytes;
+ missing_data_bytes -= cc->partial_rx.handled_bytes;
+ available_data_bytes = min(missing_data_bytes, *raw_buffer_len);
+
+ skb_put_data(cc->partial_rx.skb, raw_buffer_ptr, available_data_bytes);
+
+ /* Check if we didn't manage to copy the entire packet - got out,
+ * continue next time
+ */
+ if (available_data_bytes != missing_data_bytes) {
+ cc->partial_rx.handled_bytes += *raw_buffer_len;
+ cc->partial_rx.status = CURR_RX_DATA;
+ *raw_buffer_len = 0;
+ goto out;
+ } else {
+ *raw_buffer_len -= available_data_bytes;
+ }
+
+ /* Data fully copied */
+
+ rx_align = cc->partial_rx.desc.header_alignment;
+ if (rx_align == CC33XX_RX_BUF_PADDED)
+ skb_pull(cc->partial_rx.skb, RX_BUF_ALIGN);
+
+ extra_bytes = cc->partial_rx.desc.pad_len;
+ if (extra_bytes != 0)
+ skb_trim(cc->partial_rx.skb,
+ cc->partial_rx.skb->len - extra_bytes);
+
+ hdr = (struct ieee80211_hdr *)cc->partial_rx.skb->data;
+
+ if (ieee80211_is_beacon(hdr->frame_control))
+ beacon = 1;
+ if (ieee80211_is_probe_resp(hdr->frame_control))
+ is_probe_resp = 1;
+
+ cc33xx_rx_status(cc, &cc->partial_rx.desc,
+ IEEE80211_SKB_RXCB(cc->partial_rx.skb),
+ beacon, is_probe_resp);
+
+ seq_num = le16_get_bits(hdr->seq_ctrl, IEEE80211_SCTL_SEQ);
+ cc33xx_debug(cc->dev, DEBUG_RX, "rx skb 0x%p: %d B %s seq %d link id %d\n",
+ cc->partial_rx.skb,
+ cc->partial_rx.skb->len - cc->partial_rx.desc.pad_len,
+ beacon ? "beacon" : "", seq_num, cc->partial_rx.desc.hlid);
+
+ cc33xx_debug(cc->dev, DEBUG_RX, "rx frame. frame type 0x%x, frame length 0x%x, frame address %p\n",
+ hdr->frame_control, cc->partial_rx.skb->len,
+ cc->partial_rx.skb->data);
+
+ /* Adding frame to queue */
+ skb_queue_tail(&cc->deferred_rx_queue, cc->partial_rx.skb);
+ cc->rx_counter++;
+ cc->partial_rx.status = CURR_RX_START;
+
+ /* Make sure the deferred queues don't get too long */
+ defer_count = skb_queue_len(&cc->deferred_tx_queue);
+ defer_count += skb_queue_len(&cc->deferred_rx_queue);
+ if (defer_count >= CC33XX_RX_QUEUE_MAX_LEN)
+ cc33xx_flush_deferred_work(cc);
+ else
+ queue_work(cc->freezable_netstack_wq, &cc->netstack_work);
+
+out:
+ return (prev_buffer_len - *raw_buffer_len);
+}
+
+static int cc33xx_rx_drop_packet_data(struct cc33xx *cc, u16 *raw_buffer_len)
+{
+ u16 prev_buffer_len = *raw_buffer_len;
+
+ /* Can we drop the entire frame ? */
+ if (*raw_buffer_len >=
+ (cc->partial_rx.original_bytes - cc->partial_rx.handled_bytes)) {
+ *raw_buffer_len -= cc->partial_rx.original_bytes -
+ cc->partial_rx.handled_bytes;
+ cc->partial_rx.handled_bytes = 0;
+ cc->partial_rx.status = CURR_RX_START;
+ } else {
+ cc->partial_rx.handled_bytes += *raw_buffer_len;
+ *raw_buffer_len = 0;
+ }
+
+ return (prev_buffer_len - *raw_buffer_len);
+}
+
+/* Handle single packet from the RX buffer. We don't have to be aligned to
+ * packet boundary (buffer may start \ end in the middle of packet)
+ */
+static void cc33xx_rx_handle_packet(struct cc33xx *cc, u8 *raw_buffer_ptr,
+ u16 *raw_buffer_len)
+{
+ struct cc33xx_rx_descriptor *desc;
+ u16 consumed_bytes;
+
+ if (cc->partial_rx.status == CURR_RX_START) {
+ WARN_ON(*raw_buffer_len < 2);
+ desc = (struct cc33xx_rx_descriptor *)raw_buffer_ptr;
+ cc->partial_rx.original_bytes = le16_to_cpu(desc->length);
+ cc->partial_rx.handled_bytes = 0;
+ cc->partial_rx.status = CURR_RX_DESC;
+
+ cc33xx_debug(cc->dev, DEBUG_RX, "rx frame. desc length 0x%x, alignment 0x%x, padding 0x%x\n",
+ desc->length, desc->header_alignment, desc->pad_len);
+ }
+
+ /* start \ continue copy descriptor */
+ if (cc->partial_rx.status == CURR_RX_DESC) {
+ consumed_bytes = cc33xx_rx_get_packet_descriptor(cc,
+ raw_buffer_ptr,
+ raw_buffer_len);
+ raw_buffer_ptr += consumed_bytes;
+ }
+
+ /* Check if we are in the middle of dropped packet */
+ if (unlikely(cc->partial_rx.status == CURR_RX_DROP)) {
+ consumed_bytes = cc33xx_rx_drop_packet_data(cc, raw_buffer_len);
+ raw_buffer_ptr += consumed_bytes;
+ }
+
+ /* start \ continue copy descriptor */
+ if (cc->partial_rx.status == CURR_RX_DATA) {
+ consumed_bytes = cc33xx_rx_get_packet_data(cc, raw_buffer_ptr,
+ raw_buffer_len);
+ raw_buffer_ptr += consumed_bytes;
+ }
+}
+
+/* It is assumed that SDIO buffer was read prior to this function (data buffer
+ * is read along with the status). The RX function gets pointer to the RX data
+ * and its length. This buffer may contain unknown number of packets, separated
+ * by hif descriptor and 0-3 bytes padding if required.
+ * The last packet may be truncated in the middle, and should be saved for next
+ * iteration.
+ */
+int cc33xx_rx(struct cc33xx *cc, u8 *rx_buf_ptr, u16 rx_buf_len)
+{
+ u16 local_rx_buffer_len = rx_buf_len;
+ u16 pkt_offset = 0;
+ u16 consumed_bytes;
+ u16 prev_rx_buf_len;
+
+ /* Split data into separate packets */
+ while (local_rx_buffer_len > 0) {
+ cc33xx_debug(cc->dev, DEBUG_RX, "start loop. buffer length %d\n",
+ local_rx_buffer_len);
+
+ /* the handle data call can only fail in memory-outage
+ * conditions, in that case the received frame will just
+ * be dropped.
+ */
+ prev_rx_buf_len = local_rx_buffer_len;
+ cc33xx_rx_handle_packet(cc, rx_buf_ptr + pkt_offset,
+ &local_rx_buffer_len);
+ consumed_bytes = prev_rx_buf_len - local_rx_buffer_len;
+
+ pkt_offset += consumed_bytes;
+
+ cc33xx_debug(cc->dev, DEBUG_RX, "end rx loop. buffer length %d, packet counter %d, current packet status %d\n",
+ local_rx_buffer_len, cc->rx_counter,
+ cc->partial_rx.status);
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+int cc33xx_rx_filter_enable(struct cc33xx *cc, int index, bool enable,
+ struct cc33xx_rx_filter *filter)
+{
+ int ret;
+
+ if (!!test_bit(index, cc->rx_filter_enabled) == enable) {
+ dev_warn(cc->dev, "Request to enable an already enabled rx filter %d\n",
+ index);
+ return 0;
+ }
+
+ ret = cc33xx_acx_set_rx_filter(cc, index, enable, filter);
+
+ if (ret) {
+ dev_err(cc->dev, "Failed to %s rx data filter %d (err=%d)\n",
+ str_enable_disable(enable), index, ret);
+ return ret;
+ }
+
+ if (enable)
+ __set_bit(index, cc->rx_filter_enabled);
+ else
+ __clear_bit(index, cc->rx_filter_enabled);
+
+ return 0;
+}
+
+int cc33xx_rx_filter_clear_all(struct cc33xx *cc)
+{
+ int i, ret = 0;
+
+ for (i = 0; i < CC33XX_MAX_RX_FILTERS; i++) {
+ if (!test_bit(i, cc->rx_filter_enabled))
+ continue;
+ ret = cc33xx_rx_filter_enable(cc, i, 0, NULL);
+ if (ret)
+ return ret;
+ }
+
+ return ret;
+}
+#else
+int cc33xx_rx_filter_enable(struct cc33xx *cc, int index, bool enable,
+ struct cc33xx_rx_filter *filter)
+{
+ return 0;
+}
+
+int cc33xx_rx_filter_clear_all(struct cc33xx *cc) { return 0; }
+#endif /* CONFIG_PM */
diff --git a/drivers/net/wireless/ti/cc33xx/rx.h b/drivers/net/wireless/ti/cc33xx/rx.h
new file mode 100644
index 000000000000..d77f99fd25aa
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/rx.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __RX_H__
+#define __RX_H__
+
+/* RX Descriptor flags:
+ *
+ * Bits 0-1 - band
+ * Bit 2 - STBC
+ * Bit 3 - A-MPDU
+ * Bit 4 - HT
+ * Bits 5-7 - encryption
+ */
+#define CC33XX_RX_DESC_BAND_MASK 0x03
+#define CC33XX_RX_DESC_ENCRYPT_MASK 0xE0
+
+#define CC33XX_RX_DESC_BAND_BG 0x00
+#define CC33XX_RX_DESC_BAND_J 0x01
+#define CC33XX_RX_DESC_BAND_A 0x02
+
+/* RX Descriptor status
+ *
+ * Bits 0-2 - error code
+ * Bits 3-5 - process_id tag (AP mode FW)
+ * Bits 6-7 - reserved
+ */
+enum {
+ CC33XX_RX_DESC_SUCCESS = 0x00,
+ CC33XX_RX_DESC_DECRYPT_FAIL = 0x01,
+ CC33XX_RX_DESC_MIC_FAIL = 0x02,
+ CC33XX_RX_DESC_STATUS_MASK = 0x07
+};
+
+/* Account for the padding inserted by the FW in case of RX_ALIGNMENT
+ * or for fixing alignment in case the packet wasn't aligned.
+ */
+#define RX_BUF_ALIGN 2
+
+/* Describes the alignment state of a Rx buffer */
+enum cc33xx_rx_buf_align {
+ CC33XX_RX_BUF_ALIGNED,
+ CC33XX_RX_BUF_UNALIGNED,
+ CC33XX_RX_BUF_PADDED,
+};
+
+enum cc33xx_rx_curr_status {
+ CURR_RX_START,
+ CURR_RX_DROP,
+ CURR_RX_DESC,
+ CURR_RX_DATA
+};
+
+struct cc33xx_rx_descriptor {
+ __le16 length;
+ u8 header_alignment;
+ u8 status;
+ __le32 timestamp;
+
+ u8 flags;
+ u8 rate;
+ u8 channel;
+ s8 rssi;
+ u8 snr;
+
+ u8 hlid;
+ u8 pad_len;
+ u8 frame_format;
+} __packed;
+
+struct partial_rx_frame {
+ struct sk_buff *skb;
+ struct cc33xx_rx_descriptor desc;
+ u16 handled_bytes;
+ u16 original_bytes; /* including descriptor */
+ enum cc33xx_rx_curr_status status;
+};
+
+int cc33xx_rx(struct cc33xx *cc, u8 *rx_buf_ptr, u16 rx_buf_len);
+int cc33xx_rx_filter_enable(struct cc33xx *cc, int index, bool enable,
+ struct cc33xx_rx_filter *filter);
+int cc33xx_rx_filter_clear_all(struct cc33xx *cc);
+
+#endif /* __RX_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (9 preceding siblings ...)
2026-12-03 7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
@ 2026-12-03 7:09 ` Ramesh Ramalingam
2026-12-03 7:47 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
` (5 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:09 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
Tx of data frames starts either with MAC80211 tx op (cc33xx_op_tx)
or from the deferred IRQ context (irq_deferred_work). Both trigger
cc->tx_work (cc33xx_tx_work @ tx.c) which will call
cc33xx_tx_work_locked where data from MAC80211 SKBs will be packed
and transferred to HW. An interrupt will then be received from HW
indicating that a given frame was transmitted or expired so that its
SKB can be freed (cc33xx_tx_immediate_complete).
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/tx.c | 1133 +++++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/tx.h | 157 ++++
2 files changed, 1290 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/tx.c
create mode 100644 drivers/net/wireless/ti/cc33xx/tx.h
diff --git a/drivers/net/wireless/ti/cc33xx/tx.c b/drivers/net/wireless/ti/cc33xx/tx.c
new file mode 100644
index 000000000000..a616afd5ad3f
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/tx.c
@@ -0,0 +1,1133 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "acx.h"
+#include "debug.h"
+#include "io.h"
+#include "ps.h"
+#include "tx.h"
+#include "cc33xx.h"
+
+static int cc33xx_set_default_wep_key(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 id)
+{
+ int ret;
+ bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+
+ if (is_ap)
+ ret = cc33xx_cmd_set_default_wep_key(cc, id,
+ wlvif->ap.bcast_hlid);
+ else
+ ret = cc33xx_cmd_set_default_wep_key(cc, id, wlvif->sta.hlid);
+
+ if (ret < 0)
+ return ret;
+
+ cc33xx_debug(cc->dev, DEBUG_CRYPT, "default wep key idx: %d\n", (int)id);
+ return 0;
+}
+
+static int cc33xx_alloc_tx_id(struct cc33xx *cc, struct sk_buff *skb)
+{
+ int id;
+
+ id = find_first_zero_bit(cc->tx_frames_map, CC33XX_NUM_TX_DESCRIPTORS);
+ if (id >= CC33XX_NUM_TX_DESCRIPTORS)
+ return -EBUSY;
+
+ __set_bit(id, cc->tx_frames_map);
+ cc->tx_frames[id] = skb;
+ cc->tx_frames_cnt++;
+ cc33xx_debug(cc->dev, DEBUG_TX, "alloc desc ID. id - %d, frames count %d\n",
+ id, cc->tx_frames_cnt);
+ return id;
+}
+
+void cc33xx_free_tx_id(struct cc33xx *cc, int id)
+{
+ if (__test_and_clear_bit(id, cc->tx_frames_map)) {
+ if (unlikely(cc->tx_frames_cnt == CC33XX_NUM_TX_DESCRIPTORS))
+ clear_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags);
+
+ cc->tx_frames[id] = NULL;
+ cc->tx_frames_cnt--;
+ }
+ cc33xx_debug(cc->dev, DEBUG_TX, "free desc ID. id - %d, frames count %d\n",
+ id, cc->tx_frames_cnt);
+}
+
+static u8 cc33xx_tx_get_hlid_ap(struct cc33xx_vif *wlvif, struct sk_buff *skb,
+ struct ieee80211_sta *sta)
+{
+ struct ieee80211_hdr *hdr;
+
+ if (sta) {
+ struct cc33xx_station *wl_sta;
+
+ wl_sta = (struct cc33xx_station *)sta->drv_priv;
+ return wl_sta->hlid;
+ }
+
+ if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
+ return CC33XX_SYSTEM_HLID;
+
+ if (skb) {
+ hdr = (struct ieee80211_hdr *)skb->data;
+ if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
+ return wlvif->ap.bcast_hlid;
+ else
+ return wlvif->ap.global_hlid;
+ }
+
+ return wlvif->ap.bcast_hlid;
+}
+
+/* SKB will be NULL when called from txq based tx. dev_hlid, global_hlid
+ * shouldn't be relevant for txq cases.
+ */
+u8 cc33xx_tx_get_hlid(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct sk_buff *skb, struct ieee80211_sta *sta)
+{
+ struct ieee80211_tx_info *control;
+
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+ return cc33xx_tx_get_hlid_ap(wlvif, skb, sta);
+
+ if (skb) {
+ /* RoC packets will come through tx_pending list,
+ * SKB won't be NULL for them.
+ */
+ control = IEEE80211_SKB_CB(skb);
+ if (control->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
+ return wlvif->dev_hlid;
+ }
+
+ return wlvif->sta.hlid;
+}
+
+unsigned int cc33xx_calc_packet_alignment(struct cc33xx *cc,
+ unsigned int packet_length)
+{
+ if ((cc->quirks & CC33XX_QUIRK_TX_PAD_LAST_FRAME) ||
+ !(cc->quirks & CC33XX_QUIRK_TX_BLOCKSIZE_ALIGN))
+ return ALIGN(packet_length, CC33XX_TX_ALIGN_TO);
+ else
+ return ALIGN(packet_length, CC33XX_BUS_BLOCK_SIZE);
+}
+
+static u32 cc33xx_calc_tx_blocks(u32 len, u32 spare_blks)
+{
+ u32 blk_size = CC33XX_TX_HW_BLOCK_SIZE;
+ /* In CC33xx the packet will be stored along with its internal descriptor.
+ * the descriptor is not part of the host transaction, but should be
+ * considered as part of the allocate memory blocks in the device
+ */
+ len = len + CC33XX_INTERNAL_DESC_SIZE;
+ return (len + blk_size - 1) / blk_size + spare_blks;
+}
+
+static inline void cc33xx_set_tx_desc_blocks(struct cc33xx_tx_hw_descr *desc,
+ u32 blks)
+{
+ desc->cc33xx_mem.total_mem_blocks = blks;
+}
+
+static void cc33xx_set_tx_desc_data_len(struct cc33xx *cc,
+ struct cc33xx_tx_hw_descr *desc,
+ struct sk_buff *skb)
+{
+ desc->length = cpu_to_le16(skb->len);
+
+ /* if only the last frame is to be padded, we unset this bit on Tx */
+ if (cc->quirks & CC33XX_QUIRK_TX_PAD_LAST_FRAME)
+ desc->cc33xx_mem.ctrl = CC33XX_TX_CTRL_NOT_PADDED;
+ else
+ desc->cc33xx_mem.ctrl = 0;
+
+ cc33xx_debug(cc->dev, DEBUG_TX, "tx_fill_hdr: hlid: %d len: %d life: %d mem: %d\n",
+ desc->hlid, le16_to_cpu(desc->length),
+ le16_to_cpu(desc->life_time),
+ desc->cc33xx_mem.total_mem_blocks);
+}
+
+static int cc33xx_get_spare_blocks(struct cc33xx *cc)
+{
+ /* If we have keys requiring extra spare, indulge them */
+ if (cc->extra_spare_key_count)
+ return CC33XX_TX_HW_EXTRA_BLOCK_SPARE;
+
+ return CC33XX_TX_HW_BLOCK_SPARE;
+}
+
+int cc33xx_tx_get_queue(int queue)
+{
+ switch (queue) {
+ case 0:
+ return CONF_TX_AC_VO;
+ case 1:
+ return CONF_TX_AC_VI;
+ case 2:
+ return CONF_TX_AC_BE;
+ case 3:
+ return CONF_TX_AC_BK;
+ default:
+ return CONF_TX_AC_BE;
+ }
+}
+
+static int cc33xx_tx_allocate(struct cc33xx *cc, struct sk_buff *skb,
+ u32 extra, u32 buf_offset, u8 hlid,
+ struct nab_tx_header *nab_cmd)
+{
+ struct cc33xx_tx_hw_descr *desc;
+ u32 total_blocks;
+ int id, ret = -EBUSY, ac;
+ u32 spare_blocks;
+ u32 total_skb_len = skb->len + extra;
+ /* Add NAB command required for CC33xx architecture */
+ u32 total_len = sizeof(struct nab_tx_header);
+
+ total_skb_len += sizeof(struct cc33xx_tx_hw_descr);
+ total_len += total_skb_len;
+
+ cc33xx_debug(cc->dev, DEBUG_TX, "cc->tx_blocks_available %d\n",
+ cc->tx_blocks_available);
+
+ if (buf_offset + total_len > cc->aggr_buf_size)
+ return -EAGAIN;
+
+ spare_blocks = cc33xx_get_spare_blocks(cc);
+
+ /* allocate free identifier for the packet */
+ id = cc33xx_alloc_tx_id(cc, skb);
+ if (id < 0)
+ return id;
+
+ /* memblocks should not include nab descriptor */
+ total_blocks = cc33xx_calc_tx_blocks(total_skb_len, spare_blocks);
+ cc33xx_debug(cc->dev, DEBUG_TX, "total blocks %d\n", total_blocks);
+
+ if (total_blocks <= cc->tx_blocks_available) {
+ /**
+ * In CC33XX the packet starts with NAB command,
+ * only then the descriptor.
+ */
+ nab_cmd->sync = cpu_to_le32(CC33XX_HOST_SYNC_PATTERN);
+ nab_cmd->opcode = cpu_to_le16(CC33XX_NAB_SEND_CMD);
+
+ /**
+ * length should include the following 4 bytes
+ * of the NAB command.
+ */
+ nab_cmd->len = cpu_to_le16(total_len -
+ sizeof(struct nab_header));
+ nab_cmd->desc_length = cpu_to_le16(total_len -
+ sizeof(struct nab_tx_header));
+ nab_cmd->sd = 0;
+ nab_cmd->flags = CC33XX_NAB_SEND_FLAGS;
+
+ desc = skb_push(skb, total_skb_len - skb->len);
+
+ cc33xx_set_tx_desc_blocks(desc, total_blocks);
+
+ desc->id = id;
+
+ cc33xx_debug(cc->dev, DEBUG_TX,
+ "tx allocate id %u skb 0x%p tx_memblocks %d\n",
+ id, skb, desc->cc33xx_mem.total_mem_blocks);
+
+ cc->tx_blocks_available -= total_blocks;
+ cc->tx_allocated_blocks += total_blocks;
+
+ ac = cc33xx_tx_get_queue(skb_get_queue_mapping(skb));
+ desc->ac = ac;
+ cc->tx_allocated_pkts[ac]++;
+
+ if (test_bit(hlid, cc->links_map))
+ cc->links[hlid].allocated_pkts++;
+
+ ret = 0;
+
+ cc33xx_debug(cc->dev, DEBUG_TX,
+ "tx_allocate: size: %d, blocks: %d, id: %d\n",
+ total_len, total_blocks, id);
+ } else {
+ cc33xx_free_tx_id(cc, id);
+ }
+
+ return ret;
+}
+
+static void cc33xx_tx_fill_hdr(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct sk_buff *skb, u32 extra,
+ struct ieee80211_tx_info *control, u8 hlid)
+{
+ struct cc33xx_tx_hw_descr *desc;
+ int ac, rate_idx;
+ u16 tx_attr = 0;
+ __le16 frame_control;
+ struct ieee80211_hdr *hdr;
+ u8 *frame_start;
+ u8 session_id;
+
+ desc = (struct cc33xx_tx_hw_descr *)skb->data;
+
+ frame_start = (u8 *)(desc + 1);
+ hdr = (struct ieee80211_hdr *)(frame_start + extra);
+ frame_control = hdr->frame_control;
+
+ /* relocate space for security header */
+ if (extra) {
+ int hdrlen = ieee80211_hdrlen(frame_control);
+
+ memmove(frame_start, hdr, hdrlen);
+ skb_set_network_header(skb, skb_network_offset(skb) + extra);
+ }
+
+ if (wlvif->bss_type != BSS_TYPE_AP_BSS)
+ desc->life_time = cpu_to_le16(CC33XX_TX_HW_MGMT_PKT_LIFETIME_TU);
+ else
+ desc->life_time = cpu_to_le16(CC33XX_TX_HW_AP_MODE_PKT_LIFETIME_TU);
+
+ /* queue */
+ ac = cc33xx_tx_get_queue(skb_get_queue_mapping(skb));
+ desc->tid = skb->priority;
+
+ session_id = cc->session_ids[hlid];
+
+ if (cc->quirks & CC33XX_QUIRK_AP_ZERO_SESSION_ID &&
+ wlvif->bss_type == BSS_TYPE_AP_BSS)
+ session_id = 0;
+
+ /* configure the tx attributes */
+ tx_attr = session_id << CC33XX_TX_HW_ATTR_OFST_SESSION_COUNTER;
+
+ desc->hlid = hlid;
+ if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
+ /* if the packets are data packets
+ * send them with AP rate policies (EAPOLs are an exception),
+ * otherwise use default basic rates
+ */
+ if (skb->protocol == cpu_to_be16(ETH_P_PAE))
+ rate_idx = wlvif->sta.basic_rate_idx;
+ else if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
+ rate_idx = wlvif->sta.p2p_rate_idx;
+ else if (ieee80211_is_data(frame_control))
+ rate_idx = wlvif->sta.ap_rate_idx;
+ else
+ rate_idx = wlvif->sta.basic_rate_idx;
+ } else {
+ if (hlid == wlvif->ap.global_hlid)
+ rate_idx = wlvif->ap.mgmt_rate_idx;
+ else if (hlid == wlvif->ap.bcast_hlid ||
+ skb->protocol == cpu_to_be16(ETH_P_PAE) ||
+ !ieee80211_is_data(frame_control))
+ /* send non-data, bcast and EAPOLs using the
+ * min basic rate
+ */
+ rate_idx = wlvif->ap.bcast_rate_idx;
+ else
+ rate_idx = wlvif->ap.ucast_rate_idx[ac];
+ }
+
+ tx_attr |= rate_idx << CC33XX_TX_HW_ATTR_OFST_RATE_POLICY;
+
+ /* for WEP shared auth - no fw encryption is needed */
+ if (ieee80211_is_auth(frame_control) &&
+ ieee80211_has_protected(frame_control))
+ tx_attr |= CC33XX_TX_HW_ATTR_HOST_ENCRYPT;
+
+ /* send EAPOL frames as voice */
+ if (control->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO)
+ tx_attr |= CC33XX_TX_HW_ATTR_EAPOL_FRAME;
+
+ desc->tx_attr = cpu_to_le16(tx_attr);
+
+ cc33xx_set_tx_desc_data_len(cc, desc, skb);
+}
+
+/* caller must hold cc->mutex */
+static int cc33xx_prepare_tx_frame(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct sk_buff *skb, u32 buf_offset, u8 hlid)
+{
+ struct ieee80211_tx_info *info;
+ u32 extra = 0;
+ int ret = 0;
+ u32 total_len;
+ struct nab_tx_header nab_cmd;
+
+ if (!skb) {
+ dev_err(cc->dev, "discarding null skb\n");
+ return -EINVAL;
+ }
+
+ if (hlid == CC33XX_INVALID_LINK_ID) {
+ dev_err(cc->dev, "invalid hlid. dropping skb 0x%p\n", skb);
+ return -EINVAL;
+ }
+
+ info = IEEE80211_SKB_CB(skb);
+
+ if ((cc->quirks & CC33XX_QUIRK_TKIP_HEADER_SPACE) &&
+ info->control.hw_key &&
+ info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
+ extra = CC33XX_EXTRA_SPACE_TKIP;
+
+ if (info->control.hw_key) {
+ bool is_wep;
+ u8 idx = info->control.hw_key->hw_key_idx;
+ u32 cipher = info->control.hw_key->cipher;
+
+ is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
+ (cipher == WLAN_CIPHER_SUITE_WEP104);
+
+ if (WARN_ON(is_wep && wlvif->default_key != idx)) {
+ ret = cc33xx_set_default_wep_key(cc, wlvif, idx);
+ if (ret < 0)
+ return ret;
+ wlvif->default_key = idx;
+ }
+ }
+
+ /* Add 4 bytes gap, may be filled later on by the PMAC. */
+ extra += IEEE80211_HT_CTL_LEN;
+ ret = cc33xx_tx_allocate(cc, skb, extra, buf_offset, hlid,
+ &nab_cmd);
+ cc33xx_debug(cc->dev, DEBUG_TX, "cc33xx_tx_allocate %d\n", ret);
+
+ if (ret < 0)
+ return ret;
+
+ cc33xx_tx_fill_hdr(cc, wlvif, skb, extra, info, hlid);
+
+ /* The length of each packet is stored in terms of
+ * words. Thus, we must pad the skb data to make sure its
+ * length is aligned. The number of padding bytes is computed
+ * and set in cc33xx_tx_fill_hdr.
+ * In special cases, we want to align to a specific block size
+ * (eg. for wl128x with SDIO we align to 256).
+ */
+ total_len = cc33xx_calc_packet_alignment(cc, skb->len);
+
+ memcpy(cc->aggr_buf + buf_offset,
+ &nab_cmd, sizeof(struct nab_tx_header));
+ memcpy(cc->aggr_buf + buf_offset + sizeof(struct nab_tx_header),
+ skb->data, skb->len);
+ memset(cc->aggr_buf + buf_offset + sizeof(struct nab_tx_header)
+ + skb->len, 0, total_len - skb->len);
+
+ return (total_len + sizeof(struct nab_tx_header));
+}
+
+u32 cc33xx_tx_enabled_rates_get(struct cc33xx *cc, u32 rate_set,
+ enum nl80211_band rate_band)
+{
+ struct ieee80211_supported_band *band;
+ u32 enabled_rates = 0;
+ int bit;
+
+ band = cc->hw->wiphy->bands[rate_band];
+ for (bit = 0; bit < band->n_bitrates; bit++) {
+ if (rate_set & 0x1)
+ enabled_rates |= band->bitrates[bit].hw_value;
+ rate_set >>= 1;
+ }
+
+ /* MCS rates indication are on bits 16 - 31 */
+ rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
+
+ for (bit = 0; bit < 16; bit++) {
+ if (rate_set & 0x1)
+ enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
+ rate_set >>= 1;
+ }
+
+ return enabled_rates;
+}
+
+static inline int cc33xx_tx_get_mac80211_queue(struct cc33xx_vif *wlvif,
+ int queue)
+{
+ int mac_queue = wlvif->hw_queue_base;
+
+ switch (queue) {
+ case CONF_TX_AC_VO:
+ return mac_queue + 0;
+ case CONF_TX_AC_VI:
+ return mac_queue + 1;
+ case CONF_TX_AC_BE:
+ return mac_queue + 2;
+ case CONF_TX_AC_BK:
+ return mac_queue + 3;
+ default:
+ return mac_queue + 2;
+ }
+}
+
+static bool cc33xx_lnk_high_prio(struct cc33xx *cc, u8 hlid,
+ struct cc33xx_link *lnk)
+{
+ u8 thold;
+ struct core_fw_status *core_fw_status = &cc->core_status->fw_info;
+ unsigned long suspend_bitmap, fast_bitmap, ps_bitmap;
+
+ suspend_bitmap = le32_to_cpu(core_fw_status->link_suspend_bitmap);
+ fast_bitmap = le32_to_cpu(core_fw_status->link_fast_bitmap);
+ ps_bitmap = le32_to_cpu(core_fw_status->link_ps_bitmap);
+
+ /* suspended links are never high priority */
+ if (test_bit(hlid, &suspend_bitmap))
+ return false;
+
+ /* the priority thresholds are taken from FW */
+ if (test_bit(hlid, &fast_bitmap) && !test_bit(hlid, &ps_bitmap))
+ thold = core_fw_status->tx_fast_link_prio_threshold;
+ else
+ thold = core_fw_status->tx_slow_link_prio_threshold;
+
+ return lnk->allocated_pkts < thold;
+}
+
+static bool cc33xx_lnk_low_prio(struct cc33xx *cc, u8 hlid,
+ struct cc33xx_link *lnk)
+{
+ u8 thold;
+ struct core_fw_status *core_fw_status = &cc->core_status->fw_info;
+ unsigned long suspend_bitmap, fast_bitmap, ps_bitmap;
+
+ suspend_bitmap = le32_to_cpu(core_fw_status->link_suspend_bitmap);
+ fast_bitmap = le32_to_cpu(core_fw_status->link_fast_bitmap);
+ ps_bitmap = le32_to_cpu(core_fw_status->link_ps_bitmap);
+
+ if (test_bit(hlid, &suspend_bitmap))
+ thold = core_fw_status->tx_suspend_threshold;
+ else if (test_bit(hlid, &fast_bitmap) && !test_bit(hlid, &ps_bitmap))
+ thold = core_fw_status->tx_fast_stop_threshold;
+ else
+ thold = core_fw_status->tx_slow_stop_threshold;
+
+ return lnk->allocated_pkts < thold;
+}
+
+static inline bool cc33xx_tx_is_data_present(struct sk_buff *skb)
+{
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
+
+ return ieee80211_is_data_present(hdr->frame_control);
+}
+
+static int cc33xx_tx_buf_write(struct cc33xx *cc, u32 buf_offset)
+{
+ u32 transfer_len = 0;
+ u32 padding_size = 0;
+
+ if (!buf_offset)
+ return 0;
+
+ transfer_len = __ALIGN_MASK(buf_offset, CC33XX_BUS_BLOCK_SIZE * 2 - 1);
+ padding_size = transfer_len - buf_offset;
+ memset(cc->aggr_buf + buf_offset, 0x33, padding_size);
+
+ cc33xx_debug(cc->dev, DEBUG_TX, "sdio transaction length: %d\n", transfer_len);
+
+ return cc33xx_raw_write(cc, CC33XX_NAB_DATA_ADDR, cc->aggr_buf,
+ transfer_len, true);
+}
+
+/* Returns failure values only in case of failed bus ops within this function.
+ * cc33xx_prepare_tx_frame retvals won't be returned in order to avoid
+ * triggering recovery by higher layers when not necessary.
+ * In case a FW command fails within cc33xx_prepare_tx_frame fails a recovery
+ * will be queued in cc33xx_cmd_send. -EAGAIN/-EBUSY from prepare_tx_frame
+ * can occur and are legitimate so don't propagate. -EINVAL will emit a WARNING
+ * within prepare_tx_frame code but there's nothing we should do about those
+ * as well.
+ */
+static int cc33xx_send_txq_pkts(struct cc33xx *cc, int qid, bool low_prio_tx)
+{
+ struct cc33xx_vif *wlvif = NULL;
+ struct cc33xx_link *lnk = NULL;
+ struct ieee80211_txq *txq = NULL;
+ u8 hlid = CC33XX_INVALID_LINK_ID;
+ struct sk_buff *skb = NULL;
+ u32 buf_offset = 0;
+ int ac = CONF_TX_AC_BE;
+ int ret = 0;
+ bool tx_allowed = true;
+
+ memset(cc->aggr_buf, 0, 0x300);
+ while ((txq = ieee80211_next_txq(cc->hw, qid))) {
+ ac = cc33xx_tx_get_queue(txq->ac);
+ wlvif = cc33xx_vif_to_data(txq->vif);
+ hlid = cc33xx_tx_get_hlid(cc, wlvif, NULL, txq->sta);
+
+ /* hlid invalid. Shouldn't happen */
+ if (WARN_ON_ONCE(hlid == CC33XX_INVALID_LINK_ID)) {
+ ieee80211_return_txq(cc->hw, txq, false);
+ return -EINVAL;
+ }
+
+ lnk = &cc->links[hlid];
+ while (!cc33xx_is_queue_stopped(cc, wlvif, ac)) {
+ tx_allowed = cc33xx_lnk_high_prio(cc, hlid, lnk);
+ if (!tx_allowed && low_prio_tx)
+ tx_allowed = cc33xx_lnk_low_prio(cc, hlid, lnk);
+
+ if (!tx_allowed) {
+ set_bit(CC33XX_FLAG_TX_PENDING, &cc->flags);
+ break;
+ }
+
+ rcu_read_lock();
+ skb = ieee80211_tx_dequeue_ni(cc->hw, txq);
+ rcu_read_unlock();
+
+ if (!skb)
+ break;
+
+try_again:
+ ret = cc33xx_prepare_tx_frame(cc, wlvif, skb, buf_offset, hlid);
+ if (ret == -EAGAIN) {
+ /* Aggregation buffer is full.
+ * Flush buffer and try again.
+ */
+ ret = cc33xx_tx_buf_write(cc, buf_offset);
+ if (ret < 0) {
+ ieee80211_return_txq(cc->hw, txq, false);
+ return ret;
+ }
+ buf_offset = 0;
+ goto try_again;
+ } else if (ret == -EBUSY) {
+ /* Firmware buffer is full.
+ * Queue last skb to pending, and stop aggregating.
+ */
+ set_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags);
+ skb_queue_tail(&cc->links[hlid].tx_pending, skb);
+
+ ieee80211_return_txq(cc->hw, txq, false);
+ return cc33xx_tx_buf_write(cc, buf_offset);
+ } else if (ret < 0) {
+ ieee80211_free_txskb(cc->hw, skb);
+ } else {
+ buf_offset += ret;
+ }
+ }
+ ieee80211_return_txq(cc->hw, txq, false);
+ }
+
+ return cc33xx_tx_buf_write(cc, buf_offset);
+}
+
+static int cc33xx_send_tx_pending_pkts(struct cc33xx *cc)
+{
+ struct sk_buff *skb = NULL;
+ int hlid = CC33XX_INVALID_LINK_ID;
+ struct cc33xx_link *lnk = NULL;
+ u32 buf_offset = 0;
+ struct cc33xx_vif *wlvif = NULL;
+ int ret = 0;
+ bool tx_allowed = true;
+
+ for (hlid = 0; hlid < CC33XX_MAX_LINKS; hlid++) {
+ if (!test_bit(hlid, cc->links_map))
+ continue;
+
+ lnk = &cc->links[hlid];
+
+ /* First try high prio link, next consider high or low prio link. */
+ for (int prio = 0; prio < 2; prio++) {
+ while ((skb = skb_dequeue(&lnk->tx_pending))) {
+ struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+ struct ieee80211_vif *vif = info->control.vif;
+
+ wlvif = cc33xx_vif_to_data(vif);
+ if (unlikely(!vif || !test_bit(hlid, wlvif->links_map))) {
+ ieee80211_free_txskb(cc->hw, skb);
+ continue;
+ }
+
+ tx_allowed = cc33xx_lnk_high_prio(cc, hlid, lnk);
+ if (!tx_allowed && prio == 1)
+ tx_allowed = cc33xx_lnk_low_prio(cc, hlid, lnk);
+
+ if (!tx_allowed) {
+ skb_queue_head(&cc->links[hlid].tx_pending, skb);
+ break;
+ }
+
+try_again:
+ ret = cc33xx_prepare_tx_frame(cc, wlvif, skb, buf_offset, hlid);
+ if (ret == -EAGAIN) {
+ /* Aggregation buffer is full.
+ * Flush buffer and try again.
+ */
+ ret = cc33xx_tx_buf_write(cc, buf_offset);
+ if (ret < 0)
+ return ret;
+
+ buf_offset = 0;
+ goto try_again;
+ } else if (ret == -EBUSY) {
+ /* Firmware buffer is full.
+ * Queue back last skb, and stop aggregating.
+ */
+ set_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags);
+ skb_queue_head(&cc->links[hlid].tx_pending, skb);
+ return cc33xx_tx_buf_write(cc, buf_offset);
+ } else if (ret < 0) {
+ ieee80211_free_txskb(cc->hw, skb);
+ } else {
+ buf_offset += ret;
+ }
+ }
+ }
+ }
+
+ return cc33xx_tx_buf_write(cc, buf_offset);
+}
+
+int cc33xx_do_tx_work(struct cc33xx *cc)
+{
+ int i, j, ret;
+
+ guard(mutex)(&cc->mutex);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON ||
+ test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags)))
+ return 0;
+
+ clear_bit(CC33XX_FLAG_TX_PENDING, &cc->flags);
+
+ /* process offchannel, non-bufferable or any pending skbs */
+ ret = cc33xx_send_tx_pending_pkts(cc);
+ if (ret < 0)
+ return ret;
+
+ /* process iTXQ packets */
+ for (i = 0; i < NUM_TX_QUEUES; i++) {
+ /* First try high prio link, next consider high or
+ * low prio link.
+ */
+ for (j = 0; j < 2; j++) {
+ if (test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags))
+ return 0;
+
+ ieee80211_txq_schedule_start(cc->hw, i);
+ ret = cc33xx_send_txq_pkts(cc, i, j == 1);
+ ieee80211_txq_schedule_end(cc->hw, i);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+void cc33xx_tx_work(struct work_struct *work)
+{
+ struct cc33xx *cc = container_of(work, struct cc33xx, tx_work);
+ int ret;
+
+ ret = cc33xx_do_tx_work(cc);
+ if (ret < 0)
+ cc33xx_queue_recovery_work(cc);
+}
+
+void cc33xx_tx_reset_link_queues(struct cc33xx *cc, u8 hlid)
+{
+ struct sk_buff *skb;
+ struct ieee80211_tx_info *info;
+ struct cc33xx_link *lnk = &cc->links[hlid];
+
+ while ((skb = skb_dequeue(&lnk->tx_pending))) {
+ cc33xx_debug(cc->dev, DEBUG_TX, "link freeing skb 0x%p\n", skb);
+ info = IEEE80211_SKB_CB(skb);
+ info->status.rates[0].idx = -1;
+ info->status.rates[0].count = 0;
+ ieee80211_tx_status_ni(cc->hw, skb);
+ }
+}
+
+/* caller must *NOT* hold cc->mutex and TX must be stopped */
+void cc33xx_tx_reset_wlvif(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int i;
+
+ /* TX failure */
+ for_each_set_bit(i, wlvif->links_map, CC33XX_MAX_LINKS) {
+ if (wlvif->bss_type == BSS_TYPE_AP_BSS &&
+ i != wlvif->ap.bcast_hlid &&
+ i != wlvif->ap.global_hlid) {
+ /* this calls cc33xx_clear_link */
+ cc33xx_free_sta(cc, wlvif, i);
+ } else {
+ u8 hlid = i;
+
+ cc33xx_clear_link(cc, wlvif, &hlid);
+ }
+ }
+}
+
+int cc33xx_tx_total_queue_count(struct cc33xx *cc)
+{
+ int i, count = 0;
+
+ for (i = 0; i < CC33XX_MAX_LINKS; i++)
+ count += skb_queue_len(&cc->links[i].tx_pending);
+
+ return count;
+}
+
+/* caller must hold cc->mutex and TX must be stopped */
+void cc33xx_tx_reset(struct cc33xx *cc)
+{
+ int i;
+ struct sk_buff *skb;
+ struct ieee80211_tx_info *info;
+
+ /* only reset the queues if something bad happened */
+ if (cc33xx_tx_total_queue_count(cc) != 0) {
+ for (i = 0; i < CC33XX_MAX_LINKS; i++)
+ cc33xx_tx_reset_link_queues(cc, i);
+ }
+
+ for (i = 0; i < CC33XX_NUM_TX_DESCRIPTORS; i++) {
+ if (!cc->tx_frames[i])
+ continue;
+
+ skb = cc->tx_frames[i];
+ cc33xx_free_tx_id(cc, i);
+ cc33xx_debug(cc->dev, DEBUG_TX, "freeing skb 0x%p\n", skb);
+
+ /* Remove private headers before passing the skb to
+ * mac80211
+ */
+ info = IEEE80211_SKB_CB(skb);
+ skb_pull(skb, sizeof(struct cc33xx_tx_hw_descr));
+ if ((cc->quirks & CC33XX_QUIRK_TKIP_HEADER_SPACE) &&
+ info->control.hw_key &&
+ info->control.hw_key->cipher ==
+ WLAN_CIPHER_SUITE_TKIP) {
+ int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
+
+ memmove(skb->data + CC33XX_EXTRA_SPACE_TKIP,
+ skb->data, hdrlen);
+ skb_pull(skb, CC33XX_EXTRA_SPACE_TKIP);
+ }
+
+ info->status.rates[0].idx = -1;
+ info->status.rates[0].count = 0;
+
+ ieee80211_tx_status_ni(cc->hw, skb);
+ }
+}
+
+#define CC33XX_TX_FLUSH_TIMEOUT 500000
+
+/* caller must *NOT* hold cc->mutex */
+void cc33xx_tx_flush(struct cc33xx *cc)
+{
+ unsigned long timeout, start_time;
+ int i;
+
+ start_time = jiffies;
+ timeout = start_time + usecs_to_jiffies(CC33XX_TX_FLUSH_TIMEOUT);
+
+ /* only one flush should be in progress, for consistent queue state */
+ lockdep_assert_wiphy(cc->hw->wiphy);
+
+ mutex_lock(&cc->mutex);
+ if (cc->tx_frames_cnt == 0 && cc33xx_tx_total_queue_count(cc) == 0) {
+ mutex_unlock(&cc->mutex);
+ return;
+ }
+
+ cc33xx_stop_queues(cc, CC33XX_QUEUE_STOP_REASON_FLUSH);
+
+ while (!time_after(jiffies, timeout)) {
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "flushing tx buffer: %d %d\n",
+ cc->tx_frames_cnt,
+ cc33xx_tx_total_queue_count(cc));
+
+ /* force Tx and give the driver some time to flush data */
+ mutex_unlock(&cc->mutex);
+ if (cc33xx_tx_total_queue_count(cc))
+ cc33xx_tx_work(&cc->tx_work);
+ msleep(20);
+ mutex_lock(&cc->mutex);
+
+ if (cc->tx_frames_cnt == 0 && cc33xx_tx_total_queue_count(cc) == 0) {
+ cc33xx_debug(cc->dev, DEBUG_MAC80211, "tx flush took %d ms\n",
+ jiffies_to_msecs(jiffies - start_time));
+ goto out_wake;
+ }
+ }
+
+ dev_warn(cc->dev, "Unable to flush all TX buffers, timed out (timeout %d ms\n",
+ CC33XX_TX_FLUSH_TIMEOUT / 1000);
+
+ /* forcibly flush all Tx buffers on our queues */
+ for (i = 0; i < CC33XX_MAX_LINKS; i++)
+ cc33xx_tx_reset_link_queues(cc, i);
+
+out_wake:
+ cc33xx_wake_queues(cc, CC33XX_QUEUE_STOP_REASON_FLUSH);
+ mutex_unlock(&cc->mutex);
+}
+
+u32 cc33xx_tx_min_rate_get(u32 rate_set)
+{
+ if (WARN_ON(!rate_set))
+ return 0;
+
+ return BIT(__ffs(rate_set));
+}
+
+void cc33xx_stop_queue_locked(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 queue, enum cc33xx_queue_stop_reason reason)
+{
+ int hwq = cc33xx_tx_get_mac80211_queue(wlvif, queue);
+ bool stopped = !!cc->queue_stop_reasons[hwq];
+
+ /* queue should not be stopped for this reason */
+ WARN_ON_ONCE(test_and_set_bit(reason, &cc->queue_stop_reasons[hwq]));
+
+ if (stopped)
+ return;
+
+ ieee80211_stop_queue(cc->hw, hwq);
+}
+
+void cc33xx_stop_queues(struct cc33xx *cc,
+ enum cc33xx_queue_stop_reason reason)
+{
+ int i;
+
+ guard(spinlock_irqsave)(&cc->cc_lock);
+
+ set_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags);
+
+ /* mark all possible queues as stopped */
+ for (i = 0; i < CC33XX_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) {
+ WARN_ON_ONCE(test_and_set_bit(reason,
+ &cc->queue_stop_reasons[i]));
+ }
+
+ /* use the global version to make sure all vifs in mac80211 we don't
+ * know are stopped.
+ */
+ ieee80211_stop_queues(cc->hw);
+}
+
+void cc33xx_wake_queues(struct cc33xx *cc,
+ enum cc33xx_queue_stop_reason reason)
+{
+ int i;
+
+ guard(spinlock_irqsave)(&cc->cc_lock);
+
+ /* mark all possible queues as awake */
+ for (i = 0; i < CC33XX_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) {
+ WARN_ON_ONCE(!test_and_clear_bit(reason,
+ &cc->queue_stop_reasons[i]));
+ }
+
+ /* use the global version to make sure all vifs in mac80211 we don't
+ * know are woken up.
+ */
+ ieee80211_wake_queues(cc->hw);
+
+ clear_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags);
+
+ if (!test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags) &&
+ test_bit(CC33XX_FLAG_TX_PENDING, &cc->flags))
+ ieee80211_queue_work(cc->hw, &cc->tx_work);
+}
+
+bool cc33xx_is_queue_stopped_by_reason(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 queue,
+ enum cc33xx_queue_stop_reason reason)
+{
+ bool stopped;
+
+ guard(spinlock_irqsave)(&cc->cc_lock);
+
+ stopped = cc33xx_is_queue_stopped_by_reason_locked(cc, wlvif, queue,
+ reason);
+ return stopped;
+}
+
+bool cc33xx_is_queue_stopped_by_reason_locked(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 queue,
+ enum cc33xx_queue_stop_reason reason)
+{
+ int hwq = cc33xx_tx_get_mac80211_queue(wlvif, queue);
+
+ assert_spin_locked(&cc->cc_lock);
+ return test_bit(reason, &cc->queue_stop_reasons[hwq]);
+}
+
+bool cc33xx_is_queue_stopped(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 queue)
+{
+ int hwq = cc33xx_tx_get_mac80211_queue(wlvif, queue);
+ bool stopped;
+
+ guard(spinlock_irqsave)(&cc->cc_lock);
+ stopped = !!cc->queue_stop_reasons[hwq];
+
+ return stopped;
+}
+
+bool cc33xx_is_queue_stopped_locked(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 queue)
+{
+ int hwq = cc33xx_tx_get_mac80211_queue(wlvif, queue);
+
+ assert_spin_locked(&cc->cc_lock);
+ return !!cc->queue_stop_reasons[hwq];
+}
+
+static int cc33xx_tx_complete_packet(struct cc33xx *cc, u8 tx_stat_byte,
+ struct core_fw_status *core_fw_status)
+{
+ struct ieee80211_tx_info *info;
+ struct sk_buff *skb;
+ int id = tx_stat_byte & CC33XX_TX_STATUS_DESC_ID_MASK;
+ bool tx_success;
+ struct cc33xx_tx_hw_descr *tx_desc;
+ u16 desc_session_idx;
+
+ /* check for id legality */
+ if (unlikely(id >= CC33XX_NUM_TX_DESCRIPTORS ||
+ !cc->tx_frames[id])) {
+ dev_warn(cc->dev, "illegal id in tx completion: %d\n", id);
+
+ print_hex_dump(KERN_DEBUG, "fw_info local:",
+ DUMP_PREFIX_OFFSET, 16, 4, (u8 *)(core_fw_status),
+ sizeof(struct core_fw_status), false);
+
+ cc33xx_queue_recovery_work(cc);
+ return -EINVAL;
+ }
+
+ /* a zero bit indicates Tx success */
+ tx_success = !(tx_stat_byte & BIT(CC33XX_TX_STATUS_STAT_BIT_IDX));
+
+ skb = cc->tx_frames[id];
+ info = IEEE80211_SKB_CB(skb);
+ tx_desc = (struct cc33xx_tx_hw_descr *)skb->data;
+
+ /* update the TX status info */
+ if (tx_success && !(info->flags & IEEE80211_TX_CTL_NO_ACK))
+ info->flags |= IEEE80211_TX_STAT_ACK;
+
+ info->status.rates[0].count = 1; /* no data about retries */
+ info->status.ack_signal = -1;
+
+ if (!tx_success)
+ cc->stats.retry_count++;
+
+ /* remove private header from packet */
+ skb_pull(skb, sizeof(struct cc33xx_tx_hw_descr));
+
+ /* remove TKIP header space if present */
+ if ((cc->quirks & CC33XX_QUIRK_TKIP_HEADER_SPACE) &&
+ info->control.hw_key &&
+ info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
+ int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
+
+ memmove(skb->data + CC33XX_EXTRA_SPACE_TKIP, skb->data, hdrlen);
+ skb_pull(skb, CC33XX_EXTRA_SPACE_TKIP);
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_TX,
+ "tx status id %u skb 0x%p success %d, tx_memblocks %d\n",
+ id, skb, tx_success, tx_desc->cc33xx_mem.total_mem_blocks);
+
+ /**
+ * in order to update the memory management
+ * we should have total_blocks, ac, and hlid
+ */
+ cc->tx_blocks_available += tx_desc->cc33xx_mem.total_mem_blocks;
+ cc->tx_allocated_blocks -= tx_desc->cc33xx_mem.total_mem_blocks;
+ /* per queue */
+
+ /* prevent wrap-around in freed-packets counter */
+ cc->tx_allocated_pkts[tx_desc->ac]--;
+
+ /* per link */
+ desc_session_idx = le16_get_bits(tx_desc->tx_attr, CC33XX_TX_HW_ATTR_SESSION_COUNTER);
+
+ if (cc->session_ids[tx_desc->hlid] == desc_session_idx)
+ cc->links[tx_desc->hlid].allocated_pkts--;
+
+ cc33xx_free_tx_id(cc, id);
+
+ /* new mem blocks are available now */
+ clear_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags);
+
+ /* return the packet to the stack */
+ skb_queue_tail(&cc->deferred_tx_queue, skb);
+ queue_work(cc->freezable_wq, &cc->netstack_work);
+
+ return 0;
+}
+
+void cc33xx_tx_immediate_complete(struct cc33xx *cc)
+{
+ u8 tx_result_queue_index;
+ struct core_fw_status core_fw_status;
+ u8 i;
+ int ret = -EINVAL, tx_busy;
+
+ claim_core_status_lock(cc);
+ memcpy(&core_fw_status, &cc->core_status->fw_info,
+ sizeof(struct core_fw_status));
+
+ tx_result_queue_index = cc->core_status->fw_info.tx_result_queue_index;
+ /* Lock guarantees we shadow tx_result_queue_index NOT during
+ * an active transaction. Subsequent references to fw_info can be done
+ * without locking as long we do not pass this index.
+ */
+ release_core_status_lock(cc);
+
+ cc33xx_debug(cc->dev, DEBUG_TX, "last released desc = %d, current idx = %d\n",
+ cc->last_fw_rls_idx, tx_result_queue_index);
+
+ /* nothing to do here */
+ if (cc->last_fw_rls_idx == tx_result_queue_index)
+ return;
+
+ /* freed Tx descriptors */
+
+ if (tx_result_queue_index >= CC33XX_TX_RESULT_QUEUE_SIZE) {
+ dev_err(cc->dev, "invalid desc release index %d\n",
+ tx_result_queue_index);
+ WARN_ON(1);
+ return;
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_TX, "TX result queue! priv last fw idx %d, current result index %d\n",
+ cc->last_fw_rls_idx, tx_result_queue_index);
+
+ tx_busy = test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags);
+
+ for (i = cc->last_fw_rls_idx; i != tx_result_queue_index;
+ i = (i + 1) % CC33XX_TX_RESULT_QUEUE_SIZE) {
+ ret = cc33xx_tx_complete_packet(cc, core_fw_status.tx_result_queue[i],
+ &core_fw_status);
+ }
+
+ cc->last_fw_rls_idx = tx_result_queue_index;
+
+ /* if new mem blocks available and tx was busy or pending,
+ * queue the tx work.
+ */
+ if (!ret && !test_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags) &&
+ (tx_busy || test_bit(CC33XX_FLAG_TX_PENDING, &cc->flags)))
+ ieee80211_queue_work(cc->hw, &cc->tx_work);
+}
diff --git a/drivers/net/wireless/ti/cc33xx/tx.h b/drivers/net/wireless/ti/cc33xx/tx.h
new file mode 100644
index 000000000000..0fb6eb9a3a55
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/tx.h
@@ -0,0 +1,157 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __TX_H__
+#define __TX_H__
+
+#define CC33XX_TX_HW_BLOCK_SPARE 1
+/* for special cases - namely, TKIP */
+#define CC33XX_TX_HW_EXTRA_BLOCK_SPARE 2
+#define CC33XX_TX_HW_BLOCK_SIZE 256
+
+#define CC33XX_TX_STATUS_DESC_ID_MASK 0x7F
+#define CC33XX_TX_STATUS_STAT_BIT_IDX 7
+
+/* Indicates this TX HW frame is not padded to SDIO block size */
+#define CC33XX_TX_CTRL_NOT_PADDED BIT(7)
+
+#define CC33XX_TX_HW_MGMT_PKT_LIFETIME_TU 2000
+#define CC33XX_TX_HW_AP_MODE_PKT_LIFETIME_TU 8000
+
+#define CC33XX_TX_HW_ATTR_SESSION_COUNTER (BIT(2) | BIT(3) | BIT(4))
+#define CC33XX_TX_HW_ATTR_TX_DUMMY_REQ BIT(13)
+#define CC33XX_TX_HW_ATTR_HOST_ENCRYPT BIT(14)
+#define CC33XX_TX_HW_ATTR_EAPOL_FRAME BIT(15)
+
+#define CC33XX_TX_HW_ATTR_OFST_SESSION_COUNTER 2
+#define CC33XX_TX_HW_ATTR_OFST_RATE_POLICY 5
+
+#define CC33XX_TX_ALIGN_TO 4
+#define CC33XX_EXTRA_SPACE_TKIP 4
+#define CC33XX_EXTRA_SPACE_AES 8
+
+#define CC33XX_TX_EXTRA_HEADROOM \
+ (sizeof(struct cc33xx_tx_hw_descr) + IEEE80211_HT_CTL_LEN)
+
+/* Used for management frames */
+#define CC33XX_TID_MGMT 7
+
+/* Extend pending ROC by this time when attempting new connection (ms) */
+#define ROC_PENDING_COMPLETE_TIMEOUT 2000
+
+struct cc33xx_tx_mem {
+ /* Total number of memory blocks allocated by the host for
+ * this packet.
+ */
+ u8 total_mem_blocks;
+
+ /* control bits
+ */
+ u8 ctrl;
+} __packed;
+
+/* On cc33xx based devices, when TX packets are aggregated, each packet
+ * size must be aligned to the SDIO block size. The maximum block size
+ * is bounded by the type of the padded bytes field that is sent to the
+ * FW. The HW maximum block size is 256 bytes. We use 128 to utilize the
+ * SDIO built-in busy signal when the FIFO is full.
+ */
+#define CC33XX_BUS_BLOCK_SIZE 128
+
+struct cc33xx_tx_hw_descr {
+ /* Length of packet in words, including descriptor+header+data */
+ __le16 length;
+
+ struct cc33xx_tx_mem cc33xx_mem;
+
+ /* Packet identifier used also in the Tx-Result. */
+ u8 id;
+ /* The packet TID value (as User-Priority) */
+ u8 tid;
+ /* host link ID (HLID) */
+ u8 hlid;
+ u8 ac;
+ /* Max delay in TUs until transmission. The last device time the
+ * packet can be transmitted is: start_time + (1024 * life_time)
+ */
+ __le16 life_time;
+ /* Bitwise fields - see TX_ATTR... definitions above. */
+ __le16 tx_attr;
+} __packed;
+
+struct cc33xx_tx_hw_res_descr {
+ /* Packet Identifier - same value used in the Tx descriptor.*/
+ u8 id;
+ /* The status of the transmission, indicating success or one of
+ * several possible reasons for failure.
+ */
+ u8 status;
+ /* Total air access duration including all retrys and overheads.*/
+ __le16 medium_usage;
+ /* The time passed from host xfer to Tx-complete.*/
+ __le32 fw_handling_time;
+ /* Total media delay
+ * (from 1st EDCA AIFS counter until TX Complete).
+ */
+ __le32 medium_delay;
+ /* LS-byte of last TKIP seq-num (saved per AC for recovery). */
+ u8 tx_security_sequence_number_lsb;
+ /* Retry count - number of transmissions without successful ACK.*/
+ u8 ack_failures;
+ /* The rate that succeeded getting ACK
+ * (Valid only if status=SUCCESS).
+ */
+ u8 rate_class_index;
+ /* for 4-byte alignment. */
+ u8 spare;
+} __packed;
+
+enum cc33xx_queue_stop_reason {
+ CC33XX_QUEUE_STOP_REASON_WATERMARK,
+ CC33XX_QUEUE_STOP_REASON_FW_RESTART,
+ CC33XX_QUEUE_STOP_REASON_FLUSH,
+ CC33XX_QUEUE_STOP_REASON_SPARE_BLK, /* 18xx specific */
+};
+
+int cc33xx_tx_get_queue(int queue);
+int cc33xx_tx_total_queue_count(struct cc33xx *cc);
+void cc33xx_tx_immediate_complete(struct cc33xx *cc);
+void cc33xx_tx_work(struct work_struct *work);
+int cc33xx_do_tx_work(struct cc33xx *cc);
+void cc33xx_tx_reset_wlvif(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+void cc33xx_tx_reset(struct cc33xx *cc);
+void cc33xx_tx_flush(struct cc33xx *cc);
+u8 cc33xx_rate_to_idx(u8 rate, enum nl80211_band band);
+u32 cc33xx_tx_enabled_rates_get(struct cc33xx *cc, u32 rate_set,
+ enum nl80211_band rate_band);
+u32 cc33xx_tx_min_rate_get(u32 rate_set);
+u8 cc33xx_tx_get_hlid(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct sk_buff *skb, struct ieee80211_sta *sta);
+void cc33xx_tx_reset_link_queues(struct cc33xx *cc, u8 hlid);
+unsigned int cc33xx_calc_packet_alignment(struct cc33xx *cc,
+ unsigned int packet_length);
+void cc33xx_free_tx_id(struct cc33xx *cc, int id);
+void cc33xx_stop_queue_locked(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 queue, enum cc33xx_queue_stop_reason reason);
+void cc33xx_stop_queues(struct cc33xx *cc,
+ enum cc33xx_queue_stop_reason reason);
+void cc33xx_wake_queues(struct cc33xx *cc,
+ enum cc33xx_queue_stop_reason reason);
+bool cc33xx_is_queue_stopped_by_reason(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 queue,
+ enum cc33xx_queue_stop_reason reason);
+bool cc33xx_is_queue_stopped_by_reason_locked(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif,
+ u8 queue,
+ enum cc33xx_queue_stop_reason reason);
+bool cc33xx_is_queue_stopped_locked(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 queue);
+bool cc33xx_is_queue_stopped(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ u8 queue);
+
+/* from main.c */
+void cc33xx_free_sta(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 hlid);
+
+#endif /* __TX_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (10 preceding siblings ...)
2026-12-03 7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
@ 2026-12-03 7:09 ` Ramesh Ramalingam
2026-12-03 7:43 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h Ramesh Ramalingam
` (4 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:09 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
High-level init code for new vifs
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/init.c | 225 ++++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/init.h | 15 ++
2 files changed, 240 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/init.c
create mode 100644 drivers/net/wireless/ti/cc33xx/init.h
diff --git a/drivers/net/wireless/ti/cc33xx/init.c b/drivers/net/wireless/ti/cc33xx/init.c
new file mode 100644
index 000000000000..b0d3f927ebe8
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/init.c
@@ -0,0 +1,225 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include <linux/firmware.h>
+#include "acx.h"
+#include "cmd.h"
+#include "conf.h"
+#include "event.h"
+#include "tx.h"
+#include "init.h"
+
+static int cc33xx_init_phy_vif_config(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif)
+{
+ int ret;
+
+ ret = cc33xx_acx_slot(cc, wlvif, DEFAULT_SLOT_TIME);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int cc33xx_init_sta_beacon_filter(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif)
+{
+ int ret;
+
+ ret = cc33xx_acx_beacon_filter_table(cc, wlvif);
+ if (ret < 0)
+ return ret;
+
+ /* disable beacon filtering until we get the first beacon */
+ ret = cc33xx_acx_beacon_filter_opt(cc, wlvif, false);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int cc33xx_ap_init_templates(struct cc33xx *cc,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+
+ /* when operating as AP we want to receive external beacons for
+ * configuring ERP protection.
+ */
+ ret = cc33xx_acx_beacon_filter_opt(cc, wlvif, false);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static void cc33xx_set_ba_policies(struct cc33xx_vif *wlvif)
+{
+ /* Reset the BA RX indicators */
+ wlvif->ba_allowed = true;
+
+ /* BA is supported in STA/AP modes */
+ wlvif->ba_support = (wlvif->bss_type == BSS_TYPE_AP_BSS ||
+ wlvif->bss_type == BSS_TYPE_STA_BSS);
+}
+
+/* vif-specific initialization */
+static int cc33xx_init_sta_role(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret = cc33xx_acx_group_address_tbl(cc, true, NULL, 0);
+
+ if (ret < 0)
+ return ret;
+
+ /* Beacon filtering */
+ ret = cc33xx_init_sta_beacon_filter(cc, wlvif);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+/* vif-specific initialization */
+static int cc33xx_init_ap_role(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ int ret;
+
+ /* initialize Tx power */
+ ret = cc33xx_acx_tx_power(cc, wlvif, wlvif->power_level);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+int cc33xx_init_vif_specific(struct cc33xx *cc, struct ieee80211_vif *vif)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ struct conf_tx_settings *tx_settings = &cc->conf.host_conf.tx;
+ struct conf_tx_ac_category *conf_ac = &tx_settings->ac_conf0;
+ bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+ u8 ps_scheme = cc->conf.mac.ps_scheme;
+ int ret, i;
+
+ /* consider all existing roles before configuring psm. */
+
+ if (cc->ap_count == 0 && is_ap) { /* first AP */
+ ret = cc33xx_acx_sleep_auth(cc, CC33XX_PSM_ELP);
+ if (ret < 0)
+ return ret;
+
+ /* unmask ap events */
+ cc->event_mask |= cc->ap_event_mask;
+
+ /* first STA, no APs */
+ } else if (cc->sta_count == 0 && cc->ap_count == 0 && !is_ap) {
+ u8 sta_auth = cc->conf.host_conf.conn.sta_sleep_auth;
+ /* Configure for power according to debugfs */
+ if (sta_auth != CC33XX_PSM_ILLEGAL)
+ ret = cc33xx_acx_sleep_auth(cc, sta_auth);
+ /* Configure for ELP power saving */
+ else
+ ret = cc33xx_acx_sleep_auth(cc, CC33XX_PSM_ELP);
+
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Mode specific init */
+ if (is_ap) {
+ ret = cc33xx_init_ap_role(cc, wlvif);
+ if (ret < 0)
+ return ret;
+ } else {
+ ret = cc33xx_init_sta_role(cc, wlvif);
+ if (ret < 0)
+ return ret;
+ }
+
+ cc33xx_init_phy_vif_config(cc, wlvif);
+
+ /* Default TID/AC configuration */
+ if (WARN_ON(tx_settings->ac_conf_count != tx_settings->tid_conf_count) ||
+ WARN_ON(tx_settings->ac_conf_count != CONF_TX_MAX_AC_COUNT))
+ return -EINVAL;
+
+ for (i = 0; i < tx_settings->tid_conf_count; i++) {
+ /* If no ps poll is used, send legacy ps scheme in cmd */
+ if (ps_scheme == PS_SCHEME_NOPSPOLL)
+ ps_scheme = PS_SCHEME_LEGACY;
+
+ ret = cc33xx_tx_param_cfg(cc, wlvif, conf_ac->ac,
+ conf_ac->cw_min, conf_ac->cw_max,
+ conf_ac->aifsn, conf_ac->tx_op_limit,
+ false, ps_scheme, conf_ac->is_mu_edca,
+ conf_ac->mu_edca_aifs,
+ conf_ac->mu_edca_ecw_min_max,
+ conf_ac->mu_edca_timer);
+
+ if (ret < 0)
+ return ret;
+
+ conf_ac++;
+ }
+
+ /* Mode specific init - post mem init */
+ if (is_ap)
+ ret = cc33xx_ap_init_templates(cc, vif);
+
+ if (ret < 0)
+ return ret;
+
+ /* Configure BA sessions policies */
+ cc33xx_set_ba_policies(wlvif);
+
+ return 0;
+}
+
+int cc33xx_hw_init(struct cc33xx *cc)
+{
+ int ret;
+
+ cc->last_fw_rls_idx = 0;
+ cc->partial_rx.status = CURR_RX_START;
+
+ ret = cc33xx_acx_init_mem_config(cc);
+
+ return ret;
+}
+
+int cc33xx_download_ini_params_and_wait(struct cc33xx *cc)
+{
+ struct cc33xx_cmd_ini_params_download *cmd __free(kfree) = NULL;
+ size_t command_size = ALIGN((sizeof(*cmd) + sizeof(cc->conf)), 4);
+ int ret;
+
+ cc33xx_debug(cc->dev, DEBUG_ACX,
+ "Downloading INI configurations to FW, payload Length: %zu\n",
+ sizeof(cc->conf));
+
+ cmd = kzalloc(command_size, GFP_KERNEL);
+ if (!cmd)
+ return -ENOMEM;
+
+ cc33xx_set_max_buffer_size(cc, INI_MAX_BUFFER_SIZE);
+
+ cmd->length = cpu_to_le32(sizeof(cc->conf));
+
+ /* copy INI file params payload */
+ memcpy((cmd->payload), &cc->conf, sizeof(cc->conf));
+
+ ret = cc33xx_cmd_send(cc, CMD_DOWNLOAD_INI_PARAMS,
+ cmd, command_size, 0);
+ if (ret < 0) {
+ dev_warn(cc->dev, "download INI params to FW command sending failed: %d\n",
+ ret);
+ } else {
+ cc33xx_debug(cc->dev, DEBUG_BOOT, "INI Params downloaded successfully\n");
+ }
+
+ cc33xx_set_max_buffer_size(cc, CMD_MAX_BUFFER_SIZE);
+ return ret;
+}
diff --git a/drivers/net/wireless/ti/cc33xx/init.h b/drivers/net/wireless/ti/cc33xx/init.h
new file mode 100644
index 000000000000..5f5daebab138
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/init.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __INIT_H__
+#define __INIT_H__
+
+#include "cc33xx.h"
+
+int cc33xx_hw_init(struct cc33xx *cc);
+int cc33xx_download_ini_params_and_wait(struct cc33xx *cc);
+int cc33xx_init_vif_specific(struct cc33xx *cc, struct ieee80211_vif *vif);
+
+#endif /* __INIT_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
` (11 preceding siblings ...)
2026-12-03 7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
@ 2026-12-03 7:09 ` Ramesh Ramalingam
2026-12-03 7:52 ` sashiko-bot
[not found] ` <20261203070906.1294171-16-r-ramalingam@ti.com>
` (3 subsequent siblings)
16 siblings, 1 reply; 30+ messages in thread
From: Ramesh Ramalingam @ 2026-12-03 7:09 UTC (permalink / raw)
To: johannes, robh, krzk+dt, conor+dt, r-ramalingam
Cc: linux-wireless, devicetree, linux-kernel
From: Michael Nemanov <michael.nemanov@ti.com>
Handles the scan process.
Scan starts via cc33xx_op_hw_scan (main.c) which calls cc33xx_scan.
Scan channels are packed and sent to HW where scanning is managed by
FW concurrently to other roles without driver intervention.
Scan results are handled like normal management frames
and are sent to MAC80211. HW notifies driver of scan completion via
dedicated event which triggers a call to cc33xx_scan_completed.
Signed-off-by: Michael Nemanov <michael.nemanov@ti.com>
Signed-off-by: Ramesh Ramalingam <r-ramalingam@ti.com>
---
drivers/net/wireless/ti/cc33xx/scan.c | 842 ++++++++++++++++++++++++++
drivers/net/wireless/ti/cc33xx/scan.h | 35 ++
2 files changed, 877 insertions(+)
create mode 100644 drivers/net/wireless/ti/cc33xx/scan.c
create mode 100644 drivers/net/wireless/ti/cc33xx/scan.h
diff --git a/drivers/net/wireless/ti/cc33xx/scan.c b/drivers/net/wireless/ti/cc33xx/scan.c
new file mode 100644
index 000000000000..a109ea034396
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/scan.c
@@ -0,0 +1,842 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "cc33xx.h"
+#include "debug.h"
+#include "cmd.h"
+#include "scan.h"
+#include "tx.h"
+#include "conf.h"
+
+#define CC33XX_SCAN_TIMEOUT 30000 /* msec */
+
+#define MAX_CHANNELS_2GHZ 14
+#define MAX_CHANNELS_4GHZ 4
+#define MAX_CHANNELS_5GHZ 32
+#define CONN_SCAN_MAX_CHANNELS_ALL_BANDS 46
+
+#define SCHED_SCAN_MAX_SSIDS 16
+
+#define CONN_SCAN_MAX_BAND 2
+#define SCAN_MAX_SCHED_SCAN_PLANS 12
+
+#define SCAN_CHANNEL_FLAGS_DFS BIT(0)
+
+struct conn_scan_ch_params {
+ __le16 min_duration;
+ __le16 max_duration;
+ __le16 passive_duration;
+
+ u8 channel;
+ u8 tx_power_att;
+
+ /* bit 0: DFS channel; bit 1: DFS enabled */
+ u8 flags;
+
+ u8 padding[3];
+} __packed;
+
+enum {
+ SCAN_SSID_TYPE_PUBLIC = 0,
+ SCAN_SSID_TYPE_HIDDEN = 1,
+};
+
+enum scan_request_type {
+ SCAN_REQUEST_NONE,
+ SCAN_REQUEST_CONNECT_PERIODIC_SCAN,
+ SCAN_REQUEST_ONE_SHOT,
+ SCAN_REQUEST_SURVEY_SCAN,
+ SCAN_NUM_OF_REQUEST_TYPE
+};
+
+enum {
+ SCAN_SSID_FILTER_ANY = 0,
+ SCAN_SSID_FILTER_SPECIFIC = 1,
+ SCAN_SSID_FILTER_LIST = 2,
+ SCAN_SSID_FILTER_DISABLED = 3
+};
+
+enum {
+ SCAN_TYPE_SEARCH = 0,
+ SCAN_TYPE_PERIODIC = 1,
+ SCAN_TYPE_TRACKING = 2,
+};
+
+struct cc33xx_ssid {
+ u8 type;
+ u8 len;
+ u8 ssid[IEEE80211_MAX_SSID_LEN];
+ u8 padding[2];
+} __packed;
+
+struct cc33xx_cmd_ssid_list {
+ struct cc33xx_cmd_header header;
+
+ u8 role_id;
+ u8 scan_type;
+ u8 n_ssids;
+ struct cc33xx_ssid ssids[SCHED_SCAN_MAX_SSIDS];
+ u8 padding;
+} __packed;
+
+struct conn_scan_dwell_info {
+ __le16 min_duration;
+ __le16 max_duration;
+ __le16 passive_duration;
+} __packed;
+
+struct conn_scan_ch_info {
+ u8 channel;
+ u8 tx_power_att;
+ u8 flags;
+} __packed;
+
+struct scan_one_shot_info {
+ u8 passive[CONN_SCAN_MAX_BAND];
+ u8 active[CONN_SCAN_MAX_BAND];
+ u8 dfs;
+
+ struct conn_scan_ch_info channel_list[CONN_SCAN_MAX_CHANNELS_ALL_BANDS];
+ struct conn_scan_dwell_info dwell_info[CONN_SCAN_MAX_BAND];
+ u8 reserved;
+};
+
+struct sched_scan_plan_cmd {
+ u32 interval;
+ u32 iterations;
+};
+
+struct scan_periodic_info {
+ struct sched_scan_plan_cmd sched_scan_plans[SCAN_MAX_SCHED_SCAN_PLANS];
+ u16 sched_scan_plans_num;
+
+ u8 passive[CONN_SCAN_MAX_BAND];
+ u8 active[CONN_SCAN_MAX_BAND];
+ u8 dfs;
+
+ struct conn_scan_ch_info channel_list[CONN_SCAN_MAX_CHANNELS_ALL_BANDS];
+ struct conn_scan_dwell_info dwell_info[CONN_SCAN_MAX_BAND];
+} __packed;
+
+struct scan_param {
+ union {
+ struct scan_one_shot_info one_shot;
+ struct scan_periodic_info periodic;
+ } u;
+} __packed;
+
+struct cc33xx_cmd_scan_params {
+ struct cc33xx_cmd_header header;
+ u8 scan_type;
+ u8 role_id;
+
+ struct scan_param params;
+ s8 rssi_threshold; /* for filtering (in dBm) */
+ s8 snr_threshold; /* for filtering (in dB) */
+
+ u8 bssid[ETH_ALEN];
+ u8 padding[2];
+
+ u8 ssid_from_list; /* use ssid from configured ssid list */
+ u8 filter; /* forward only results with matching ssids */
+
+ u8 num_of_ssids;
+} __packed;
+
+#define MAX_EXTRA_IES_LEN 512
+
+struct cc33xx_cmd_set_ies {
+ struct cc33xx_cmd_header header;
+ u8 scan_type;
+ u8 role_id;
+ __le16 len;
+ u8 data[MAX_EXTRA_IES_LEN];
+} __packed;
+
+struct cc33xx_cmd_scan_stop {
+ struct cc33xx_cmd_header header;
+
+ u8 scan_type;
+ u8 role_id;
+ u8 is_ET;
+ u8 padding;
+} __packed;
+
+struct cc33xx_scan_channels {
+ u8 passive[CONN_SCAN_MAX_BAND]; /* number of passive scan channels */
+ u8 active[CONN_SCAN_MAX_BAND]; /* number of active scan channels */
+ u8 dfs; /* number of dfs channels in 5ghz */
+ u8 passive_active; /* number of passive before active channels 2.4ghz */
+
+ struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ];
+ struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ];
+ struct conn_scan_ch_params channels_4[MAX_CHANNELS_4GHZ];
+};
+
+static void cc33xx_adjust_channels(struct scan_param *scan_param,
+ struct cc33xx_scan_channels *cmd_channels,
+ enum scan_request_type scan_type)
+{
+ struct conn_scan_ch_info *ch_info_list;
+ struct conn_scan_dwell_info *dwell_info;
+ struct conn_scan_ch_params *channel;
+ struct conn_scan_ch_params *ch_params_list;
+
+ u8 *passive;
+ u8 *dfs;
+ u8 *active;
+ int i, j;
+ u8 band;
+
+ if (scan_type == SCAN_REQUEST_CONNECT_PERIODIC_SCAN) {
+ ch_info_list = scan_param->u.periodic.channel_list;
+ dwell_info = scan_param->u.periodic.dwell_info;
+ active = (u8 *)&scan_param->u.periodic.active;
+ passive = (u8 *)&scan_param->u.periodic.passive;
+ dfs = (u8 *)&scan_param->u.periodic.dfs;
+ } else {
+ ch_info_list = scan_param->u.one_shot.channel_list;
+ dwell_info = scan_param->u.one_shot.dwell_info;
+ active = (u8 *)&scan_param->u.one_shot.active;
+ passive = (u8 *)&scan_param->u.one_shot.passive;
+ dfs = (u8 *)&scan_param->u.one_shot.dfs;
+ }
+
+ memcpy(passive, cmd_channels->passive, sizeof(cmd_channels->passive));
+ memcpy(active, cmd_channels->active, sizeof(cmd_channels->active));
+ *dfs = cmd_channels->dfs;
+
+ ch_params_list = cmd_channels->channels_2;
+ for (i = 0; i < MAX_CHANNELS_2GHZ; ++i) {
+ ch_info_list[i].channel = ch_params_list[i].channel;
+ ch_info_list[i].flags = ch_params_list[i].flags;
+ ch_info_list[i].tx_power_att = ch_params_list[i].tx_power_att;
+ }
+
+ channel = &ch_params_list[0];
+ band = NL80211_BAND_2GHZ;
+ dwell_info[band].min_duration = channel->min_duration;
+ dwell_info[band].max_duration = channel->max_duration;
+ dwell_info[band].passive_duration = channel->passive_duration;
+
+ ch_params_list = cmd_channels->channels_5;
+ for (j = 0; j < MAX_CHANNELS_5GHZ; ++i, ++j) {
+ ch_info_list[i].channel = ch_params_list[j].channel;
+ ch_info_list[i].flags = ch_params_list[j].flags;
+ ch_info_list[i].tx_power_att = ch_params_list[j].tx_power_att;
+ }
+
+ channel = &ch_params_list[0];
+ band = NL80211_BAND_5GHZ;
+ dwell_info[band].min_duration = channel->min_duration;
+ dwell_info[band].max_duration = channel->max_duration;
+ dwell_info[band].passive_duration = channel->passive_duration;
+}
+
+static int cc33xx_cmd_build_probe_req(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 role_id,
+ u8 scan_type, const u8 *ssid,
+ size_t ssid_len, const u8 *ie0,
+ size_t ie0_len, const u8 *ie1,
+ size_t ie1_len)
+{
+ struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
+ struct sk_buff *skb = NULL;
+ struct cc33xx_cmd_set_ies *cmd __free(kfree) = NULL;
+ int ret;
+
+ cmd = kzalloc_obj(*cmd);
+ if (!cmd)
+ return -ENOMEM;
+
+ skb = ieee80211_probereq_get(cc->hw, vif->addr, ssid,
+ ssid_len, ie0_len + ie1_len);
+ if (!skb)
+ return -ENOMEM;
+
+ if (ie0_len)
+ skb_put_data(skb, ie0, ie0_len);
+
+ if (ie1_len)
+ skb_put_data(skb, ie1, ie1_len);
+
+ cmd->scan_type = scan_type;
+ cmd->role_id = role_id;
+
+ cmd->len = cpu_to_le16(skb->len - sizeof(struct ieee80211_hdr_3addr));
+
+ if (skb->data) {
+ memcpy(cmd->data,
+ skb->data + sizeof(struct ieee80211_hdr_3addr), le16_to_cpu(cmd->len));
+ }
+
+ usleep_range(10000, 11000);
+ ret = cc33xx_cmd_send(cc, CMD_SET_PROBE_IE, cmd, sizeof(*cmd), 0);
+
+ if (ret < 0)
+ dev_warn(cc->dev, "cmd set_template failed: %d\n", ret);
+
+ dev_kfree_skb(skb);
+ return ret;
+}
+
+static void cc33xx_started_vifs_iter(void *data, u8 *mac,
+ struct ieee80211_vif *vif)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ bool active = false;
+ int *count = (int *)data;
+
+ /* count active interfaces according to interface type.
+ * checking only bss_conf.idle is bad for some cases, e.g.
+ * we don't want to count sta in p2p_find as active interface.
+ */
+ switch (wlvif->bss_type) {
+ case BSS_TYPE_STA_BSS:
+ if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+ active = true;
+ break;
+
+ case BSS_TYPE_AP_BSS:
+ if (wlvif->cc->active_sta_count > 0)
+ active = true;
+ break;
+
+ default:
+ break;
+ }
+
+ if (active)
+ (*count)++;
+}
+
+static int cc33xx_count_started_vifs(struct cc33xx *cc)
+{
+ int count = 0;
+
+ ieee80211_iterate_active_interfaces_atomic(cc->hw,
+ IEEE80211_IFACE_ITER_RESUME_ALL,
+ cc33xx_started_vifs_iter,
+ &count);
+ return count;
+}
+
+static int cc33xx_scan_get_channels(struct cc33xx *cc,
+ struct ieee80211_channel *req_channels[],
+ u32 n_channels, u32 n_ssids,
+ struct conn_scan_ch_params *channels,
+ u32 band, bool radar, bool passive,
+ unsigned int start, unsigned int max_channels,
+ u8 *n_pactive_ch, int scan_type)
+{
+ unsigned int i, j;
+ u32 flags;
+ bool force_passive = !n_ssids;
+ u32 min_dwell_time_active, max_dwell_time_active;
+ u32 dwell_time_passive, dwell_time_dfs;
+ struct conn_scan_ch_params *ch;
+ struct ieee80211_channel *req_ch;
+
+ /* configure dwell times according to scan type */
+ if (scan_type == SCAN_TYPE_SEARCH) {
+ struct conf_scan_settings *c = &cc->conf.host_conf.scan;
+ bool active_vif_exists = !!cc33xx_count_started_vifs(cc);
+
+ min_dwell_time_active = active_vif_exists ?
+ c->min_dwell_time_active :
+ c->min_dwell_time_active_long;
+ max_dwell_time_active = active_vif_exists ?
+ c->max_dwell_time_active :
+ c->max_dwell_time_active_long;
+ dwell_time_passive = c->dwell_time_passive;
+ dwell_time_dfs = c->dwell_time_dfs;
+ } else {
+ struct conf_sched_scan_settings *c =
+ &cc->conf.host_conf.sched_scan;
+ u32 delta_per_probe;
+
+ delta_per_probe = (band == NL80211_BAND_5GHZ) ?
+ c->dwell_time_delta_per_probe_5 :
+ c->dwell_time_delta_per_probe;
+
+ min_dwell_time_active = c->base_dwell_time +
+ n_ssids * c->num_probe_reqs * delta_per_probe;
+
+ max_dwell_time_active = min_dwell_time_active;
+ max_dwell_time_active += c->max_dwell_time_delta;
+ dwell_time_passive = c->dwell_time_passive;
+ dwell_time_dfs = c->dwell_time_dfs;
+ }
+
+ min_dwell_time_active = DIV_ROUND_UP(min_dwell_time_active, 1000);
+ max_dwell_time_active = DIV_ROUND_UP(max_dwell_time_active, 1000);
+ dwell_time_passive = DIV_ROUND_UP(dwell_time_passive, 1000);
+ dwell_time_dfs = DIV_ROUND_UP(dwell_time_dfs, 1000);
+
+ for (i = 0, j = start; i < n_channels && j < max_channels; i++) {
+ flags = req_channels[i]->flags;
+ ch = &channels[j];
+ req_ch = req_channels[i];
+
+ if (force_passive)
+ flags |= IEEE80211_CHAN_NO_IR;
+
+ if (req_ch->band == band && !(flags & IEEE80211_CHAN_DISABLED) &&
+ (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
+ /* if radar is set, we ignore the passive flag */
+ (radar || !!(flags & IEEE80211_CHAN_NO_IR) == passive)) {
+ if (flags & IEEE80211_CHAN_RADAR) {
+ ch->flags |= SCAN_CHANNEL_FLAGS_DFS;
+
+ ch->passive_duration =
+ cpu_to_le16(dwell_time_dfs);
+ } else {
+ ch->passive_duration =
+ cpu_to_le16(dwell_time_passive);
+ }
+
+ ch->min_duration = cpu_to_le16(min_dwell_time_active);
+ ch->max_duration = cpu_to_le16(max_dwell_time_active);
+
+ ch->tx_power_att = req_ch->max_power;
+ ch->channel = req_ch->hw_value;
+
+ if (n_pactive_ch && band == NL80211_BAND_2GHZ &&
+ ch->channel >= 12 && ch->channel <= 14 &&
+ (flags & IEEE80211_CHAN_NO_IR) && !force_passive) {
+ /* pactive channels treated as DFS */
+ ch->flags = SCAN_CHANNEL_FLAGS_DFS;
+
+ /* n_pactive_ch is counted down from the end of
+ * the passive channel list
+ */
+ (*n_pactive_ch)++;
+ cc33xx_debug(cc->dev, DEBUG_SCAN, "n_pactive_ch = %d\n",
+ *n_pactive_ch);
+ }
+
+ cc33xx_debug(cc->dev, DEBUG_SCAN, "freq %d, ch. %d, flags 0x%x, power %d, min/max_dwell %d/%d%s%s\n",
+ req_ch->center_freq, req_ch->hw_value,
+ req_ch->flags, req_ch->max_power,
+ min_dwell_time_active,
+ max_dwell_time_active,
+ flags & IEEE80211_CHAN_RADAR ? ", DFS" : "",
+ flags & IEEE80211_CHAN_NO_IR ? ", NO-IR" : "");
+ j++;
+ }
+ }
+
+ return j - start;
+}
+
+static bool cc33xx_set_scan_chan_params(struct cc33xx *cc,
+ struct cc33xx_scan_channels *cfg,
+ struct ieee80211_channel *channels[],
+ u32 n_channels, u32 n_ssids,
+ int scan_type)
+{
+ u8 n_pactive_ch = 0;
+
+ cfg->passive[0] = cc33xx_scan_get_channels(cc, channels, n_channels,
+ n_ssids, cfg->channels_2,
+ NL80211_BAND_2GHZ, false,
+ true, 0, MAX_CHANNELS_2GHZ,
+ &n_pactive_ch, scan_type);
+
+ cfg->active[0] = cc33xx_scan_get_channels(cc, channels, n_channels,
+ n_ssids, cfg->channels_2,
+ NL80211_BAND_2GHZ, false,
+ false, cfg->passive[0],
+ MAX_CHANNELS_2GHZ,
+ &n_pactive_ch, scan_type);
+
+ cfg->passive[1] = cc33xx_scan_get_channels(cc, channels, n_channels,
+ n_ssids, cfg->channels_5,
+ NL80211_BAND_5GHZ, false,
+ true, 0, MAX_CHANNELS_5GHZ,
+ &n_pactive_ch, scan_type);
+
+ cfg->dfs = cc33xx_scan_get_channels(cc, channels, n_channels, n_ssids,
+ cfg->channels_5, NL80211_BAND_5GHZ,
+ true, true, cfg->passive[1],
+ MAX_CHANNELS_5GHZ, &n_pactive_ch,
+ scan_type);
+
+ cfg->active[1] = cc33xx_scan_get_channels(cc, channels, n_channels,
+ n_ssids, cfg->channels_5,
+ NL80211_BAND_5GHZ, false,
+ false,
+ cfg->passive[1] + cfg->dfs,
+ MAX_CHANNELS_5GHZ,
+ &n_pactive_ch, scan_type);
+
+ cfg->passive_active = n_pactive_ch;
+
+ cc33xx_debug(cc->dev, DEBUG_SCAN, "2.4GHz: active %d passive %d\n",
+ cfg->active[0], cfg->passive[0]);
+ cc33xx_debug(cc->dev, DEBUG_SCAN, "5GHz: active %d passive %d\n",
+ cfg->active[1], cfg->passive[1]);
+ cc33xx_debug(cc->dev, DEBUG_SCAN, "DFS: %d\n", cfg->dfs);
+
+ return cfg->passive[0] || cfg->active[0] || cfg->passive[1] ||
+ cfg->active[1] || cfg->dfs;
+}
+
+static int cc33xx_scan_send(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cfg80211_scan_request *req)
+{
+ struct cc33xx_cmd_scan_params *cmd __free(kfree) = NULL;
+ struct cc33xx_scan_channels *cmd_channels __free(kfree) = NULL;
+ struct cc33xx_ssid *cmd_ssid;
+ u16 alloc_size;
+ int ret;
+ int i;
+
+ alloc_size = sizeof(*cmd) + (sizeof(struct cc33xx_ssid) * req->n_ssids);
+ cmd = kzalloc(alloc_size, GFP_KERNEL);
+ if (!cmd)
+ return -ENOMEM;
+
+ /* scan on the dev role if the regular one is not started */
+ if (cc33xx_is_p2p_mgmt(wlvif))
+ cmd->role_id = wlvif->dev_role_id;
+ else
+ cmd->role_id = wlvif->role_id;
+
+ if (WARN_ON(cmd->role_id == CC33XX_INVALID_ROLE_ID))
+ return -EINVAL;
+
+ cmd->scan_type = SCAN_REQUEST_ONE_SHOT;
+ cmd->rssi_threshold = -127;
+ cmd->snr_threshold = 0;
+
+ for (i = 0; i < ETH_ALEN; i++)
+ cmd->bssid[i] = req->bssid[i];
+ cmd->ssid_from_list = 0;
+ cmd->filter = 0;
+ WARN_ON(req->n_ssids > 1);
+
+ /* configure channels */
+ cmd_channels = kzalloc_obj(*cmd_channels);
+ if (!cmd_channels)
+ return -ENOMEM;
+
+ cc33xx_set_scan_chan_params(cc, cmd_channels, req->channels,
+ req->n_channels, req->n_ssids,
+ SCAN_TYPE_SEARCH);
+
+ cc33xx_adjust_channels(&cmd->params, cmd_channels, cmd->scan_type);
+ if (req->n_ssids > 0) {
+ cmd->ssid_from_list = 1;
+ cmd->num_of_ssids = req->n_ssids;
+ cmd_ssid = (struct cc33xx_ssid *)((u8 *)cmd + sizeof(*cmd));
+
+ cmd_ssid->len = req->ssids[0].ssid_len;
+ memcpy(cmd_ssid->ssid, req->ssids[0].ssid, cmd_ssid->len);
+ cmd_ssid->type = (req->ssids[0].ssid_len) ?
+ SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
+ }
+
+ ret = cc33xx_cmd_build_probe_req(cc, wlvif, cmd->role_id, cmd->scan_type,
+ req->ssids ? req->ssids[0].ssid : NULL,
+ req->ssids ? req->ssids[0].ssid_len : 0,
+ req->ie, req->ie_len, NULL, 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "PROBE request template failed\n");
+ return ret;
+ }
+
+ cc33xx_dump(DEBUG_SCAN, "SCAN: ", cmd, alloc_size);
+
+ ret = cc33xx_cmd_send(cc, CMD_SCAN, cmd, alloc_size, 0);
+ if (ret < 0)
+ dev_err(cc->dev, "SCAN failed\n");
+
+ return ret;
+}
+
+static int cc33xx_scan_sched_scan_ssid_list(struct cc33xx_vif *wlvif,
+ struct cfg80211_sched_scan_request *req,
+ struct cc33xx_cmd_ssid_list *cmd)
+{
+ struct cfg80211_match_set *sets = req->match_sets;
+ struct cfg80211_ssid *ssids = req->ssids;
+ int i, j, n_match_ssids = 0;
+
+ /* count the match sets that contain SSIDs */
+ for (i = 0; i < req->n_match_sets; i++) {
+ if (sets[i].ssid.ssid_len > 0)
+ n_match_ssids++;
+ }
+
+ /* No filter, no ssids or only bcast ssid */
+ if (!n_match_ssids && (!req->n_ssids ||
+ (req->n_ssids == 1 && req->ssids[0].ssid_len == 0)))
+ return 0;
+
+ cmd->role_id = wlvif->role_id;
+ if (!n_match_ssids) {
+ /* No filter, with ssids */
+
+ for (i = 0; i < req->n_ssids; i++) {
+ cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ?
+ SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
+ cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len;
+ memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid,
+ ssids[i].ssid_len);
+ cmd->n_ssids++;
+ }
+ } else {
+ /* Add all SSIDs from the filters */
+ for (i = 0; i < req->n_match_sets; i++) {
+ /* ignore sets without SSIDs */
+ if (!sets[i].ssid.ssid_len)
+ continue;
+
+ cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC;
+ cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len;
+ memcpy(cmd->ssids[cmd->n_ssids].ssid,
+ sets[i].ssid.ssid, sets[i].ssid.ssid_len);
+ cmd->n_ssids++;
+ }
+ if (req->n_ssids > 1 || (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) {
+ /* Mark all the SSIDs passed in the SSID list as HIDDEN,
+ * so they're used in probe requests.
+ */
+ for (i = 0; i < req->n_ssids; i++) {
+ if (!req->ssids[i].ssid_len)
+ continue;
+
+ for (j = 0; j < cmd->n_ssids; j++) {
+ if (req->ssids[i].ssid_len == cmd->ssids[j].len &&
+ !memcmp(req->ssids[i].ssid,
+ cmd->ssids[j].ssid,
+ req->ssids[i].ssid_len)) {
+ cmd->ssids[j].type =
+ SCAN_SSID_TYPE_HIDDEN;
+ break;
+ }
+ }
+ /* Fail if SSID isn't present in the filters */
+ if (j == cmd->n_ssids)
+ return -EINVAL;
+ }
+ }
+ }
+
+ return cmd->n_ssids;
+}
+
+int cc33xx_sched_scan_start(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cfg80211_sched_scan_request *req,
+ struct ieee80211_scan_ies *ies)
+{
+ struct cc33xx_cmd_scan_params *cmd __free(kfree) = NULL;
+ struct cc33xx_cmd_ssid_list *ssid_list __free(kfree) = NULL;
+ struct cc33xx_scan_channels *cmd_channels __free(kfree) = NULL;
+ struct conf_sched_scan_settings *c = &cc->conf.host_conf.sched_scan;
+ int ret;
+ int n_ssids = 0;
+ int alloc_size = sizeof(*cmd);
+
+ ssid_list = kzalloc_obj(*ssid_list);
+ if (!ssid_list)
+ return -ENOMEM;
+
+ n_ssids = cc33xx_scan_sched_scan_ssid_list(wlvif, req, ssid_list);
+ if (n_ssids < 0)
+ return -EINVAL;
+
+ if (n_ssids <= 5) {
+ alloc_size += (n_ssids * sizeof(struct cc33xx_ssid));
+ } else { /* n_ssids > 5 */
+ ssid_list->scan_type = SCAN_REQUEST_CONNECT_PERIODIC_SCAN;
+ ret = cc33xx_cmd_send(cc, CMD_CONNECTION_SCAN_SSID_CFG,
+ ssid_list, sizeof(*ssid_list), 0);
+ if (ret < 0) {
+ dev_err(cc->dev, "cmd sched scan ssid list failed\n");
+ return ret;
+ }
+ }
+
+ cmd = kzalloc(alloc_size, GFP_KERNEL);
+ if (!cmd)
+ return -ENOMEM;
+
+ cmd->role_id = wlvif->role_id;
+
+ if (WARN_ON(cmd->role_id == CC33XX_INVALID_ROLE_ID))
+ return -EINVAL;
+
+ cmd->scan_type = SCAN_REQUEST_CONNECT_PERIODIC_SCAN;
+ cmd->rssi_threshold = c->rssi_threshold;
+ cmd->snr_threshold = c->snr_threshold;
+
+ cmd->filter = 1;
+ cmd->num_of_ssids = n_ssids;
+
+ cc33xx_debug(cc->dev, DEBUG_CMD, "ssid list num of n_ssids %d\n", n_ssids);
+ if (n_ssids > 0 && n_ssids <= 5) {
+ cmd->ssid_from_list = 1;
+ memcpy((u8 *)cmd + sizeof(*cmd), ssid_list->ssids,
+ n_ssids * sizeof(struct cc33xx_ssid));
+ }
+
+ cmd_channels = kzalloc_obj(*cmd_channels);
+ if (!cmd_channels)
+ return -ENOMEM;
+
+ /* configure channels */
+ cc33xx_set_scan_chan_params(cc, cmd_channels, req->channels,
+ req->n_channels, req->n_ssids,
+ SCAN_TYPE_PERIODIC);
+ cc33xx_adjust_channels(&cmd->params, cmd_channels, cmd->scan_type);
+
+ memcpy(cmd->params.u.periodic.sched_scan_plans, req->scan_plans,
+ sizeof(struct sched_scan_plan_cmd) * req->n_scan_plans);
+
+ cmd->params.u.periodic.sched_scan_plans_num = req->n_scan_plans;
+
+ cc33xx_debug(cc->dev, DEBUG_SCAN,
+ "interval[0]: %d, iterations[0]: %d, num_plans: %d\n",
+ cmd->params.u.periodic.sched_scan_plans[0].interval,
+ cmd->params.u.periodic.sched_scan_plans[0].iterations,
+ cmd->params.u.periodic.sched_scan_plans_num);
+
+ ret = cc33xx_cmd_build_probe_req(cc, wlvif, cmd->role_id, cmd->scan_type,
+ req->ssids ? req->ssids[0].ssid : NULL,
+ req->ssids ? req->ssids[0].ssid_len : 0,
+ ies->ies[NL80211_BAND_2GHZ],
+ ies->len[NL80211_BAND_2GHZ],
+ ies->common_ies,
+ ies->common_ie_len);
+
+ if (ret < 0) {
+ dev_err(cc->dev, "PROBE request template failed\n");
+ return ret;
+ }
+
+ cc33xx_dump(DEBUG_SCAN, "SCAN: ", cmd, alloc_size);
+
+ ret = cc33xx_cmd_send(cc, CMD_SCAN, cmd, alloc_size, 0);
+ if (ret < 0)
+ dev_err(cc->dev, "SCAN failed\n");
+
+ return ret;
+}
+
+static int __cc33xx_scan_stop(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif, u8 scan_type)
+{
+ struct cc33xx_cmd_scan_stop *stop __free(kfree) = NULL;
+ int ret;
+
+ stop = kzalloc_obj(*stop);
+ if (!stop)
+ return -ENOMEM;
+
+ stop->role_id = wlvif->role_id;
+ stop->scan_type = scan_type;
+
+ ret = cc33xx_cmd_send(cc, CMD_STOP_SCAN, stop, sizeof(*stop), 0);
+ if (ret < 0)
+ dev_err(cc->dev, "failed to send sched scan stop command\n");
+
+ return ret;
+}
+
+void cc33xx_scan_sched_scan_stop(struct cc33xx *cc,
+ struct cc33xx_vif *wlvif)
+{
+ __cc33xx_scan_stop(cc, wlvif, SCAN_REQUEST_CONNECT_PERIODIC_SCAN);
+}
+
+static int cc33xx_scan_start(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cfg80211_scan_request *req)
+{
+ return cc33xx_scan_send(cc, wlvif, req);
+}
+
+int cc33xx_scan_stop(struct cc33xx *cc, struct cc33xx_vif *wlvif)
+{
+ return __cc33xx_scan_stop(cc, wlvif, SCAN_REQUEST_ONE_SHOT);
+}
+
+void cc33xx_scan_complete_work(struct wiphy *wiphy,
+ struct wiphy_work *work)
+
+{
+ struct cc33xx *cc;
+ struct cfg80211_scan_info info = {
+ .aborted = false,
+ };
+
+ cc = container_of(work, struct cc33xx, scan_complete_work.work);
+
+ if (unlikely(cc->state != CC33XX_STATE_ON))
+ return;
+
+ if (cc->scan.state == CC33XX_SCAN_STATE_IDLE)
+ return;
+
+ cc->scan.state = CC33XX_SCAN_STATE_IDLE;
+ cc->scan.req = NULL;
+ cc->scan_wlvif = NULL;
+
+ if (cc->scan.failed) {
+ dev_info(cc->dev, "Scan completed due to error.\n");
+ cc33xx_queue_recovery_work(cc);
+ }
+
+ ieee80211_scan_completed(cc->hw, &info);
+}
+
+int cc33xx_scan(struct cc33xx *cc, struct ieee80211_vif *vif, const u8 *ssid,
+ size_t ssid_len, struct cfg80211_scan_request *req)
+{
+ struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
+ int ret;
+
+ if (cc->scan.state != CC33XX_SCAN_STATE_IDLE)
+ return -EBUSY;
+
+ cc->scan.state = CC33XX_SCAN_STATE_ACTIVE;
+
+ if (ssid_len && ssid) {
+ cc->scan.ssid_len = ssid_len;
+ memcpy(cc->scan.ssid, ssid, ssid_len);
+ } else {
+ cc->scan.ssid_len = 0;
+ }
+
+ /* we assume failure so that timeout scenarios are handled correctly */
+ cc->scan.failed = true;
+
+ ret = cc33xx_scan_start(cc, wlvif, req);
+ if (ret < 0) {
+ dev_err(cc->dev, "Failed to start scan: %d\n", ret);
+ cc->scan.state = CC33XX_SCAN_STATE_IDLE;
+ return ret;
+ }
+
+ cc->scan_wlvif = wlvif;
+ cc->scan.req = req;
+
+ wiphy_delayed_work_queue(cc->hw->wiphy, &cc->scan_complete_work,
+ msecs_to_jiffies(CC33XX_SCAN_TIMEOUT));
+
+ return ret;
+}
+
+void cc33xx_scan_completed(struct cc33xx *cc)
+{
+ wiphy_lock(cc->hw->wiphy);
+ if (cc->scan_wlvif) {
+ cc->scan.failed = false;
+ wiphy_delayed_work_queue(cc->hw->wiphy, &cc->scan_complete_work,
+ msecs_to_jiffies(0));
+ }
+ wiphy_unlock(cc->hw->wiphy);
+}
diff --git a/drivers/net/wireless/ti/cc33xx/scan.h b/drivers/net/wireless/ti/cc33xx/scan.h
new file mode 100644
index 000000000000..cb463f428493
--- /dev/null
+++ b/drivers/net/wireless/ti/cc33xx/scan.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ *
+ * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#ifndef __SCAN_H__
+#define __SCAN_H__
+
+#include "cc33xx.h"
+
+enum {
+ CC33XX_SCAN_STATE_IDLE,
+ CC33XX_SCAN_STATE_ACTIVE,
+ CC33XX_SCAN_STATE_DONE
+};
+
+int cc33xx_scan_stop(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+void cc33xx_scan_completed(struct cc33xx *cc);
+int cc33xx_sched_scan_start(struct cc33xx *cc, struct cc33xx_vif *wlvif,
+ struct cfg80211_sched_scan_request *req,
+ struct ieee80211_scan_ies *ies);
+void cc33xx_scan_sched_scan_stop(struct cc33xx *cc, struct cc33xx_vif *wlvif);
+
+int cc33xx_scan(struct cc33xx *cc, struct ieee80211_vif *vif,
+ const u8 *ssid, size_t ssid_len,
+ struct cfg80211_scan_request *req);
+void cc33xx_scan_complete_work(struct wiphy *wiphy,
+ struct wiphy_work *work);
+
+static inline void cc33xx_scan_sched_scan_results(struct cc33xx *cc)
+{
+ ieee80211_sched_scan_results(cc->hw);
+}
+
+#endif /* __CC33XX_SCAN_H__ */
--
2.34.1
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml
2026-12-03 7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
@ 2026-12-03 7:20 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:20 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: net: wireless: subject repeats cc33xx and includes
.yaml
--
commit 430185d1e3f122c525bb2d504fad8043c9b15616
Author: Michael Nemanov <michael.nemanov@ti.com>
dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml
This commit adds the devicetree binding schema for the Texas Instruments
CC33xx SDIO wireless LAN controller family.
> dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml
[Severity: Low]
Could the subject drop the redundant ".yaml" suffix and repeated "cc33xx"?
Documentation/devicetree/bindings/submitting-patches.rst recommends
omitting YAML references since the prefix implies it, so a subject like
"dt-bindings: net: wireless: Add TI CC33xx" would match the convention.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=1
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 03/17] wifi: cc33xx: Add debug.h
2026-12-03 7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
@ 2026-12-03 7:26 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:26 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] wifi: cc33xx: debug.h is not self-contained due to missing
kernel includes
- [Low] wifi: cc33xx: debug macros and debug_level are no-ops without
DYNAMIC_DEBUG
--
commit f51a97b31fa519e45c24343fe1cf9fecb56c8f46
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add debug.h
This commit adds the debug header for the cc33xx wireless driver, defining
debug level bitmasks and logging macros for debug messages and hex dumps.
> diff --git a/drivers/net/wireless/ti/cc33xx/debug.h b/drivers/net/wireless/ti/cc33xx/debug.h
> new file mode 100644
> index 0000000000000..0f47942d4ecbf
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/debug.h
> @@ -0,0 +1,70 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
> + */
> +
> +#ifndef __DEBUG_H__
> +#define __DEBUG_H__
> +
> +#define DRIVER_NAME "cc33xx"
> +#define DRIVER_PREFIX DRIVER_NAME ": "
> +
> +enum {
> + DEBUG_NONE = 0,
> + DEBUG_IRQ = BIT(0),
[ ... ]
> + DEBUG_ALL = GENMASK(31, 0),
> + DEBUG_NO_DATAPATH = (DEBUG_ALL & ~DEBUG_IRQ & ~DEBUG_TX & ~DEBUG_RX & ~DEBUG_CORE_STATUS),
> +};
> +
> +extern u32 cc33xx_debug_level;
[Severity: Low]
Should debug.h include the kernel headers it depends on so it can be
compiled standalone?
The header has no #include directives, yet uses BIT(), GENMASK(), and u32
at file scope, and its macros expand unlikely(), dev_dbg(),
print_hex_dump_debug(), DUMP_PREFIX_OFFSET, min_t(), size_t, and true.
Including debug.h standalone or before cc33xx.h will fail to compile.
[ ... ]
> +#define cc33xx_debug(dev, level, fmt, arg...) \
> + do { \
> + if (unlikely((level) & cc33xx_debug_level)) \
> + dev_dbg(dev, fmt, ##arg); \
> + } while (0)
> +
> +#define cc33xx_dump(level, prefix, buf, len) \
> + do { \
> + if ((level) & cc33xx_debug_level) \
> + print_hex_dump_debug(DRIVER_PREFIX prefix, \
> + DUMP_PREFIX_OFFSET, 16, 1, \
> + buf, \
> + min_t(size_t, len, DEBUG_DUMP_LIMIT), \
> + 0); \
> + } while (0)
> +
> +#define cc33xx_dump_ascii(level, prefix, buf, len) \
> + do { \
> + if ((level) & cc33xx_debug_level) \
> + print_hex_dump_debug(DRIVER_PREFIX prefix, \
> + DUMP_PREFIX_OFFSET, 16, 1, \
> + buf, \
> + min_t(size_t, len, DEBUG_DUMP_LIMIT), \
> + true); \
> + } while (0)
[Severity: Low]
Do cc33xx_debug(), cc33xx_dump(), and cc33xx_dump_ascii() become no-ops
when CONFIG_DYNAMIC_DEBUG is disabled?
Without CONFIG_DYNAMIC_DEBUG or -DDEBUG (which commit "wifi: cc33xx: Add
Kconfig, Makefile" does not set), dev_dbg() compiles to dev_no_printk()
and print_hex_dump_debug() is an empty stub. Writing to debug_level
from commit "wifi: cc33xx: Add main.c" then silently produces no output.
A !CONFIG_DYNAMIC_DEBUG fallback to dev_printk(KERN_DEBUG, ...) and
print_hex_dump(), as in fc3d1db5b60e ("wlcore: make debug prints work
without dynamic debug"), would need cc33xx_debug_level to default to
DEBUG_NONE in that build to avoid flooding boot logs.
When CONFIG_DYNAMIC_DEBUG is enabled, the DEBUG_NO_DATAPATH default also
inverts the unlikely() hint in cc33xx_debug() for non-datapath callsites
while double-gating datapath logs behind both dyndbg and debug_level.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=3
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h
2026-12-03 7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
@ 2026-12-03 7:31 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:31 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] wifi: cc33xx: cc33xx_rx_filter_field mixes wire layout and
host pointer
- [Low] wifi: cc33xx: duplicate struct ieee80211_hdr_3addr as struct
ieee80211_header
- [Low] wifi: cc33xx: CC33XX_AGGR_BUFFER_SIZE scales with host PAGE_SIZE
--
commit 4b0d2195b69f9a28c77203d691ab37987f0041e3
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add cc33xx.h, cc33xx_i.h
This commit adds the common internal header files cc33xx.h and cc33xx_i.h
defining core driver structures, hardware constants, and vif, link, and
RX filter types for the cc33xx wireless driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/cc33xx.h b/drivers/net/wireless/ti/cc33xx/cc33xx.h
> new file mode 100644
> index 0000000000000..0ace1b1f557d5
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/cc33xx.h
> @@ -0,0 +1,445 @@
[ ... ]
> +#define CC33XX_AGGR_BUFFER_SIZE (8 * PAGE_SIZE)
[Severity: Low]
Should CC33XX_AGGR_BUFFER_SIZE use a fixed size such as SZ_32K instead of
scaling with PAGE_SIZE?
On 16 KiB or 64 KiB page kernels, (8 * PAGE_SIZE) expands to 128 KiB or
512 KiB. In commit "wifi: cc33xx: Add main.c", cc33xx_alloc_hw() passes
get_order(CC33XX_AGGR_BUFFER_SIZE) to __get_free_pages(), forcing an
order-3 contiguous allocation and wasting up to 448 KiB per device.
[ ... ]
> diff --git a/drivers/net/wireless/ti/cc33xx/cc33xx_i.h b/drivers/net/wireless/ti/cc33xx/cc33xx_i.h
> new file mode 100644
> index 0000000000000..c0d739713c2ab
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/cc33xx_i.h
> @@ -0,0 +1,415 @@
[ ... ]
> +struct ieee80211_header {
> + __le16 frame_ctl;
> + __le16 duration_id;
> + u8 da[ETH_ALEN];
> + u8 sa[ETH_ALEN];
> + u8 bssid[ETH_ALEN];
> + __le16 seq_ctl;
> + u8 payload[];
> +} __packed;
[Severity: Low]
Can this reuse struct ieee80211_hdr_3addr from linux/ieee80211.h instead
of defining struct ieee80211_header?
cc33xx_i.h already includes linux/ieee80211.h via net/mac80211.h, which
defines the same 24-byte 3-address MAC header. Using the generic
ieee80211_ prefix risks colliding with future core headers, and u8
payload[] is unused since callers only take sizeof(struct ieee80211_header).
[ ... ]
> +struct cc33xx_rx_filter_field {
> + __le16 offset;
> + u8 len;
> + u8 flags;
> + u8 *pattern;
> +} __packed;
[Severity: Medium]
Will copying pattern bytes into &field->pattern trigger a
CONFIG_FORTIFY_SOURCE warning?
struct cc33xx_rx_filter_field mixes the 4-byte wire header with a host
pointer u8 *pattern (at an unaligned 4-byte offset on 64-bit hosts). In
commit "wifi: cc33xx: Add acx.c, acx.h", cc33xx_rx_filter_flatten_fields()
overlays it onto the firmware buffer:
drivers/net/wireless/ti/cc33xx/acx.c:cc33xx_rx_filter_flatten_fields() {
...
field = (struct cc33xx_rx_filter_field *)buf;
...
memcpy(&field->pattern, filter->fields[i].pattern, field->len);
}
Because pattern is a scalar pointer rather than a flexible array member,
suspending with a WoWLAN pattern longer than sizeof(u8 *) (up to
RX_FILTER_MAX_PATTERN_SIZE, 91 bytes) hits fortify_warn_once() (and panics
under panic_on_warn=1) via cc33xx_op_suspend() -> cc33xx_configure_wowlan().
Splitting the wire-format descriptor with a flexible array u8 pattern[]
from the host-side struct cc33xx_rx_filter_field avoids the field-spanning
write and the unaligned pointer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=2
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h
2026-12-03 7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
@ 2026-12-03 7:31 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:31 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] wifi: cc33xx: deferred PEER_REMOVE_COMPLETE deadlocks
wiphy_lock and suspend
- [Medium] wifi: cc33xx: cc33xx_event_beacon_loss() resets
connection_loss_work timer
- [Medium] wifi: cc33xx: unbounded wlvif->role_id in test_bit() stack
read in event.c
- [Medium] wifi: cc33xx: init_completion() races with complete() on
peer_remove_complete
- [Low] wifi: cc33xx: WARN_ON() on firmware length mismatch and OOM in
deffer_event()
- [Low] wifi: cc33xx: unprefixed global event symbols and misspelled
deffer_event()
- [Low] wifi: cc33xx: missing includes in event.h and unused includes in
event.c
--
commit f05cf8502f1ced3131244955cb016c8c83fc1b09
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add event.c, event.h
This commit adds the firmware event handling code for the cc33xx driver,
queueing event mailbox payloads onto a lockless list to be processed
outside IRQ context.
> diff --git a/drivers/net/wireless/ti/cc33xx/event.c b/drivers/net/wireless/ti/cc33xx/event.c
> new file mode 100644
> index 0000000000000..04653a727a2a9
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/event.c
[ ... ]
> +void deffer_event(struct cc33xx *cc,
> + const void *event_payload, size_t event_length)
> +{
> + struct event_node *event_node;
> +
> + if (WARN_ON(event_length != sizeof(event_node->event_data)))
> + return;
> +
> + event_node = kzalloc_obj(*event_node);
> + if (WARN_ON(!event_node))
> + return;
[Severity: Low]
Should these WARN_ON() calls be replaced with ratelimited error logging
or a plain return?
event_length comes directly from the firmware header in
parse_control_message(), so a malformed message will trigger a kernel
warning (and panic systems with panic_on_warn=1) instead of logging a
device error. Likewise, kzalloc_obj() already warns on GFP_KERNEL
allocation failure, making WARN_ON(!event_node) redundant.
> + memcpy(&event_node->event_data,
> + event_payload, sizeof(event_node->event_data));
> +
> + llist_add(&event_node->node, &cc->event_list);
> + queue_work(cc->freezable_wq, &cc->irq_deferred_work);
> +}
[Severity: High]
Can deferring PEER_REMOVE_COMPLETE_EVENT_ID onto cc->event_list and
cc->freezable_wq deadlock with wiphy_lock and hang system suspend?
cc33xx_cmd_remove_peer() runs under wiphy_lock (from drv_sta_state()) and
waits 5000 ms for cc->peer_remove_complete, queueing hardware recovery on
timeout. In process_deferred_events(), PEER_REMOVE_COMPLETE_EVENT_ID is
handled last on cc->irq_deferred_work, after six handlers that take
wiphy_lock:
CPU0 (mac80211) CPU1 (irq_deferred_work)
drv_sta_state()
wiphy_lock(wiphy)
cc33xx_cmd_remove_peer()
wait_for_completion_timeout(
&cc->peer_remove_complete)
process_deferred_events()
cc33xx_event_max_tx_failure()
wiphy_lock(wiphy) <-- blocks
/* never reaches complete() */
The same 5-second timeout and spurious recovery also happen
deterministically per station during suspend, because
suspend_freeze_processes() freezes cc->freezable_wq before
wiphy_suspend() -> cfg80211_leave_all() tears down AP peers.
Since complete(&cc->peer_remove_complete) does not sleep and requires no
locks, completing it directly in deffer_event() would avoid both hangs.
[ ... ]
> +static void cc33xx_event_channel_switch(struct cc33xx *cc,
> + unsigned long roles_bitmap,
> + bool success)
> +{
> + struct cc33xx_vif *wlvif;
> + struct ieee80211_vif *vif;
> +
> + wiphy_lock(cc->hw->wiphy);
> + cc33xx_for_each_wlvif(cc, wlvif) {
> + if (wlvif->role_id == CC33XX_INVALID_ROLE_ID ||
> + !test_bit(wlvif->role_id, &roles_bitmap))
> + continue;
[Severity: Medium]
Can test_bit(wlvif->role_id, &roles_bitmap) read out of bounds on the
stack?
cc33xx_cmd_role_enable() copies the firmware-supplied u8 role_id without
checking it against CC33XX_MAX_ROLES, and both
cc33xx_event_channel_switch() and cc33xx_event_beacon_loss() only reject
CC33XX_INVALID_ROLE_ID. If firmware returns a role_id >= BITS_PER_LONG,
test_bit() reads past the single unsigned long roles_bitmap on the stack.
Checking wlvif->role_id >= CC33XX_MAX_ROLES here (and in
cc33xx_event_beacon_loss() and cc33xx_cmd_role_enable()) would prevent
this.
[ ... ]
> +static void cc33xx_event_peer_remove_complete(struct cc33xx *cc)
> +{
> + complete(&cc->peer_remove_complete);
> +}
[Severity: Medium]
Can complete(&cc->peer_remove_complete) race with init_completion() in
cc33xx_cmd_remove_peer() or dereference an uninitialized waitqueue?
cc33xx_cmd_remove_peer() calls init_completion(&cc->peer_remove_complete)
on every peer removal without serializing against irq_deferred_work.
After a timeout, a late event can race with the next removal:
CPU0 (cc33xx_cmd_remove_peer) CPU1 (irq_deferred_work)
init_completion(
&cc->peer_remove_complete)
cc33xx_event_peer_remove_complete()
complete(&cc->peer_remove_complete)
raw_spin_lock_irqsave(&x->wait.lock)
init_swait_queue_head(&x->wait) <-- overwrites held lock / task_list
In addition, cc33xx_alloc_hw() never initializes cc->peer_remove_complete,
so an unsolicited event before the first peer removal will hit a NULL
pointer dereference on the zeroed waitqueue head. Initializing it once in
cc33xx_alloc_hw() and using reinit_completion() in
cc33xx_cmd_remove_peer() avoids both issues.
[ ... ]
> + /* if the work is already queued, it should take place.
> + * We don't want to delay the connection loss
> + * indication any more.
> + */
> + wiphy_delayed_work_queue(cc->hw->wiphy,
> + &wlvif->connection_loss_work,
> + msecs_to_jiffies(delay));
[Severity: Medium]
Does wiphy_delayed_work_queue() postpone connection_loss_work on every
repeated BSS_LOSS_EVENT_ID?
When delay is non-zero, wiphy_delayed_work_queue() unconditionally calls
mod_timer(), overwriting an existing deadline. Repeated beacon loss
events within that window will keep pushing the timer out, leaving a
non-P2P station stuck on a dead BSS without disconnecting.
Guarding the call with wiphy_delayed_work_pending() would preserve the
original deadline as the comment describes.
[ ... ]
> diff --git a/drivers/net/wireless/ti/cc33xx/event.h b/drivers/net/wireless/ti/cc33xx/event.h
> new file mode 100644
> index 0000000000000..21cde2f96be96
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/event.h
> @@ -0,0 +1,62 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
> + */
> +
> +#ifndef __EVENT_H__
> +#define __EVENT_H__
[ ... ]
> +enum {
> + RSSI_SNR_TRIGGER_0_EVENT_ID = BIT(0),
[Severity: Low]
Should event.h include linux/bits.h and linux/types.h for BIT() and
size_t so it compiles standalone? Also, event.c includes ps.h and io.h
without using any declarations from either header.
[ ... ]
> +void deffer_event(struct cc33xx *cc, const void *event_payload, size_t event_length);
> +void process_deferred_events(struct cc33xx *cc);
> +void flush_deferred_event_list(struct cc33xx *cc);
[Severity: Low]
Should these global functions use the cc33xx_ prefix (and fix the
"deffer_event" spelling to cc33xx_defer_event())? Since CONFIG_CC33XX is
tristate, unprefixed names like process_deferred_events() and
flush_deferred_event_list() enter the global kernel namespace when
built-in.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=7
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h
2026-12-03 7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
@ 2026-12-03 7:32 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:32 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [Medium] wifi: cc33xx: wrong HE PHY cap byte read in
cc33xx_acx_set_peer_cap()
- [Medium] wifi: cc33xx: out-of-bounds read on zero tx_rate in
cc33xx_acx_get_tx_rate()
- [Medium] wifi: cc33xx: missing le16_to_cpu() on tx_rate in
cc33xx_acx_get_tx_rate()
- [Medium] wifi: cc33xx: FORTIFY_SOURCE write in
cc33xx_rx_filter_flatten_fields()
- [Medium] wifi: cc33xx: truncated vendor IE entry in
cc33xx_acx_beacon_filter_table()
- [Medium] wifi: cc33xx: firmware status ignored in
cc33xx_acx_set_ba_receiver_session()
- [Medium] wifi: cc33xx: off-by-8 CMD_INTERROGATE bounds check in
__cc33xx_cmd_send()
- [Medium] wifi: cc33xx: native-endian fields in firmware ACX response
structs
- [Medium] wifi: cc33xx: concurrent init_completion() re-init races with
complete()
- [Low] wifi: cc33xx: UB walk past bcn_filt_ie0 in
cc33xx_acx_beacon_filter_table()
- [Low] wifi: cc33xx: error masked as -ENOMEM in cc33xx_acx_statistics()
- [Low] wifi: cc33xx: split __free(kfree) NULL declarations in acx.c
- [Low] wifi: cc33xx: unused cc33xx_acx_statistics() exceeds command
buffer size
--
commit 5acddfafa58fc73efd39d8a631b1de2d03702bb8
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add acx.c, acx.h
This commit adds the ACX firmware configuration and interrogation helpers
along with their wire-format structures for the cc33xx wireless driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/acx.c b/drivers/net/wireless/ti/cc33xx/acx.c
> new file mode 100644
> index 0000000000000..b9a56bd26358a
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/acx.c
> @@ -0,0 +1,767 @@
[ ... ]
> +int cc33xx_acx_clear_statistics(struct cc33xx *cc)
> +{
> + struct acx_header *acx __free(kfree) = NULL;
> + int ret = 0;
> +
> + acx = kzalloc_obj(*acx);
> + if (!acx)
> + return -ENOMEM;
[Severity: Low]
This isn't a bug, but across all 23 allocating functions in this file the
__free(kfree) pointer is declared as NULL at the top and assigned later
(including before early returns such as in cc33xx_acx_beacon_filter_opt()).
Initializing it in a single statement at the allocation site follows the
cleanup API convention.
> + ret = cc33xx_cmd_configure(cc, ACX_CLEAR_STATISTICS, acx, sizeof(*acx));
[Severity: Medium]
Can calling __cc33xx_cmd_send() from these ACX helpers race with a late
command completion?
Every ACX configure, interrogate, and debug helper calls into
__cc33xx_cmd_send() (added in commit "wifi: cc33xx: Add cmd.c, cmd.h"),
which calls init_completion(&cc->command_complete) on every command. If a
previous command timed out or was sent asynchronously, a late completion in
parse_control_message() runs without cc->cmd_lock while the next command
re-initializes the completion's wait.lock and task_list:
CPU0 CPU1
__cc33xx_cmd_send()
wait_for_completion_timeout()
-> times out (-EIO)
__cc33xx_cmd_send()
guard(mutex)(&cc->cmd_lock)
parse_control_message()
complete(&cc->command_complete)
raw_spin_lock(&x->wait.lock)
init_completion(&cc->command_complete) <-- overwrites wait.lock/list
The same pattern appears in cc33xx_cmd_remove_peer() with
cc->peer_remove_complete, and neither completion is initialized during
cc33xx_alloc_hw(). Initializing both once at allocation time and calling
reinit_completion() before each wait would avoid re-initializing an in-use
lock.
[ ... ]
> +static int cc33xx_acx_mem_map(struct cc33xx *cc,
> + struct acx_header *memory_map, size_t len)
> +{
> + int ret;
> +
> + ret = cc33xx_cmd_interrogate(cc, MEM_MAP_INTR, memory_map,
> + sizeof(struct acx_header), len);
[Severity: Medium]
Can this and the other ACX interrogate callers overflow their kzalloc_obj()
buffers by up to 8 bytes?
All interrogate helpers here pass sizeof(*buf) (which includes the 8-byte
struct nab_header) as res_len, but __cc33xx_cmd_send() checks
cc->result_length against res_len before copying into buf + sizeof(struct
nab_header):
drivers/net/wireless/ti/cc33xx/cmd.c:__cc33xx_cmd_send() {
...
if (WARN_ON(cc->result_length > res_len)) {
dev_err(cc->dev, "Error, insufficient response buffer\n");
return -EINVAL;
}
switch (id) {
case CMD_INTERROGATE:
case CMD_DEBUG_READ:
case CMD_TEST_MODE:
case CMD_BM_READ_DEVICE_INFO:
memcpy(buf + sizeof(struct nab_header), cc->command_result,
cc->result_length);
break;
...
}
If firmware returns a cc->result_length in (res_len - 8, res_len], the
check passes and memcpy() writes past the end of the allocated struct.
Checking res_len >= sizeof(struct nab_header) and cc->result_length <=
res_len - sizeof(struct nab_header) for these commands would prevent the
overflow.
[ ... ]
> +int cc33xx_acx_beacon_filter_table(struct cc33xx *cc, struct cc33xx_vif *wlvif)
> +{
> + struct acx_beacon_filter_ie_table *ie_table __free(kfree) = NULL;
> + struct conf_bcn_filt_rule *r = &cc->conf.host_conf.conn.bcn_filt_ie0;
> + struct conf_bcn_filt_rule *itr_end;
> + int idx = 0;
> + int ret;
> + bool vendor_spec = false;
> +
> + if (WARN_ON(cc->conf.host_conf.conn.bcn_filt_ie_count > CONF_MAX_BCN_FILT_IE_COUNT))
> + return -EINVAL;
> +
> + itr_end = r + cc->conf.host_conf.conn.bcn_filt_ie_count;
[Severity: Low]
Does advancing r past bcn_filt_ie0 invoke undefined behavior when
bcn_filt_ie_count > 1?
In struct conf_conn_settings, bcn_filt_ie0 through bcn_filt_ie31 are
individual scalar struct members rather than an array, so pointer
arithmetic across them risks -Warray-bounds warnings or subobject-bounds
issues. Replacing them with an array bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT]
would avoid walking past a scalar member.
[ ... ]
> + while (r < itr_end) {
> + ie_table->table[idx++] = r->ie;
> + ie_table->table[idx++] = r->rule;
> +
> + /* only one vendor specific ie allowed */
> + if (r->ie == WLAN_EID_VENDOR_SPECIFIC && !vendor_spec) {
> + /* for vendor specific rules configure the
> + * additional fields
> + */
> + memcpy(&ie_table->table[idx], r->oui,
> + CONF_BCN_IE_OUI_LEN);
> + idx += CONF_BCN_IE_OUI_LEN;
> + ie_table->table[idx++] = r->type;
> + memcpy(&ie_table->table[idx], r->version,
> + CONF_BCN_IE_VER_LEN);
> + idx += CONF_BCN_IE_VER_LEN;
> + vendor_spec = true;
> + }
> +
> + ie_table->num_ie++;
> + r++;
> + }
[Severity: Medium]
Does this write a truncated IE 221 entry when cc33xx-conf.bin contains more
than one WLAN_EID_VENDOR_SPECIFIC rule?
When vendor_spec is already true, r->ie and r->rule are still written and
ie_table->num_ie is still incremented, but the mandatory 6-byte OUI, type,
and version fields are omitted, causing firmware to misparse the following
entries as vendor-specific data. Duplicate vendor-specific rules should be
skipped before writing to ie_table->table[] and incrementing num_ie.
[ ... ]
> +int cc33xx_acx_statistics(struct cc33xx *cc, void *stats)
> +{
> + int ret;
> +
> + ret = cc33xx_cmd_interrogate(cc, ACX_STATISTICS, stats,
> + sizeof(struct acx_header),
> + sizeof(struct cc33xx_acx_statistics));
[Severity: Low]
Can cc33xx_acx_statistics() ever succeed with the current command buffer
size?
struct cc33xx_acx_statistics is 1104 bytes, while read_control_message()
and struct cc33xx::command_result are capped at CC33XX_CMD_MAX_SIZE (896
bytes), so a full firmware response would be rejected with -EIO and a
command timeout. Since cc33xx_acx_statistics() has no callers in the
series, should this dead code be removed or its buffer size fixed?
> + if (ret < 0) {
> + dev_warn(cc->dev, "acx statistics failed: %d\n", ret);
> + return -ENOMEM;
> + }
[Severity: Low]
Should this return ret instead of -ENOMEM? cc33xx_acx_statistics() does
not allocate memory, so returning -ENOMEM discards the actual error from
cc33xx_cmd_interrogate().
[ ... ]
> + ret = cc33xx_cmd_configure_failsafe(cc, BA_SESSION_RX_SETUP_CFG,
> + acx, sizeof(*acx),
> + BIT(CMD_STATUS_NO_RX_BA_SESSION));
> + if (ret < 0) {
> + dev_warn(cc->dev, "acx ba receiver session failed: %d\n", ret);
> + return ret;
> + }
> +
> + /* sometimes we can't start the session */
> + if (ret == CMD_STATUS_NO_RX_BA_SESSION) {
> + dev_warn(cc->dev, "no fw rx ba on tid %d\n", tid_index);
> + return -EBUSY;
> + }
[Severity: Medium]
Can the CMD_STATUS_NO_RX_BA_SESSION branch ever be reached?
cc33xx_cmd_configure_failsafe() calls __cc33xx_cmd_send() with res_len = 0,
which returns CMD_STATUS_SUCCESS unconditionally without inspecting the
firmware command-complete status in cc->command_result. As a result, when
firmware rejects an RX BA session, cc33xx_acx_set_ba_receiver_session()
returns 0 instead of -EBUSY and cc33xx_op_ampdu_action() records the
session as active in host state.
[ ... ]
> + if (acx->tx_rate >= CONF_HW_RATE_INDEX_MCS0)
> + sinfo->txrate.mcs = acx->tx_rate - CONF_HW_RATE_INDEX_MCS0;
> + else
> + sinfo->txrate.legacy = cc33xx_idx_to_rate_100kbps[acx->tx_rate - 1];
[Severity: Medium]
Can this read out of bounds before cc33xx_idx_to_rate_100kbps[] if firmware
reports acx->tx_rate == 0?
When acx->tx_rate is 0 (for example before any frame has been transmitted
or on a short response leaving the kzalloc zero value), acx->tx_rate - 1
evaluates to -1 and reads 2 bytes before the array.
[Severity: Medium]
Is acx->tx_rate missing a le16_to_cpu() conversion here?
struct acx_preamble_and_tx_rate declares u16 tx_rate instead of __le16, so
on big-endian hosts a little-endian legacy rate index like 1 is read as
0x0100, taking the MCS branch and reporting a bogus TX bitrate to
userspace.
[ ... ]
> + memcpy(&field->pattern, filter->fields[i].pattern, field->len);
> + buf += sizeof(struct cc33xx_rx_filter_field) - sizeof(u8 *);
> + buf += field->len;
[Severity: Medium]
Will this memcpy() trigger a CONFIG_FORTIFY_SOURCE field-spanning write
warning whenever a WoWLAN pattern is longer than sizeof(u8 *)?
In struct cc33xx_rx_filter_field, pattern is a u8 * pointer rather than a
flexible array member, while WoWLAN advertises patterns up to 91 bytes.
Using a packed wire struct with a u8 pattern[] flexible array member (or
copying to buf + offsetof(struct cc33xx_rx_filter_field, pattern)) would
avoid tripping fortify_memcpy_chk().
[ ... ]
> + cap_info = he_cap->he_cap_elem.phy_cap_info;
> + acx->nominal_packet_padding = (cap_info[8] & NOMINAL_PACKET_PADDING);
[Severity: Medium]
Should this read cap_info[9] instead of cap_info[8]?
In include/linux/ieee80211-he.h, bits [7:6] (0xc0) of phy_cap_info[8] are
IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_MASK, whereas Nominal Packet Padding is
in phy_cap_info[9] (IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK). This
programs the peer's DCM Max RU bits as the HE packet extension duration on
every 802.11ax association. It also leaves the value unshifted rather than
shifting right by IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_POS (6), which
is worth checking against the firmware ABI.
> diff --git a/drivers/net/wireless/ti/cc33xx/acx.h b/drivers/net/wireless/ti/cc33xx/acx.h
> new file mode 100644
> index 0000000000000..43b6c4b16c574
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/acx.h
[ ... ]
> +struct cc33xx_roaming_stats {
> + s32 rssi_level;
> +} __packed;
[Severity: Medium]
Should rssi_level here be __le32 (and tx_rate in struct
acx_preamble_and_tx_rate be __le16) to match the other packed firmware
response structures?
Declaring wire-format fields with native-endian types breaks sparse
endianness checks and produces byte-swapped values on big-endian hosts.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=6
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h
2026-12-03 7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
@ 2026-12-03 7:33 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:33 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] wifi: cc33xx: concurrent cc33xx_flush_deferred_work() races
with netstack_work
- [High] wifi: cc33xx: desc->length underflow causes infinite loop or
OOB read in rx.c
- [High] wifi: cc33xx: unchecked nab_rx_header->len causes OOB read in
cc33xx_rx()
- [High] wifi: cc33xx: teardown ordering UAF in cc33xx_remove() and
cc33xx_turn_off()
- [Medium] wifi: cc33xx: OOB read on split descriptor in
cc33xx_rx_handle_packet()
- [Medium] wifi: cc33xx: missing skb->len checks in
cc33xx_rx_get_packet_data()
- [Medium] wifi: cc33xx: partial_rx.skb leaked on firmware recovery and
driver removal
- [Medium] wifi: cc33xx: cc33xx_rx_status() passes unsupported rate_idx
to mac80211
- [Low] wifi: cc33xx: unratelimited dev_warn()/dev_err() in RX path
under cc->mutex
- [Low] wifi: cc33xx: missing le16_to_cpu() on __le16 fields in rx.c
debug logs
- [Low] wifi: cc33xx: double subtraction of pad_len in
cc33xx_rx_get_packet_data()
--
commit 0a5e47272fafbb9009679e3984d494d3dc15af9f
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add rx.c, rx.h
This commit adds RX buffer parsing, descriptor handling, and RX filter
helpers for the TI CC33xx wireless driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/rx.c b/drivers/net/wireless/ti/cc33xx/rx.c
> new file mode 100644
> index 0000000000000..81e16749ed0be
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/rx.c
> @@ -0,0 +1,385 @@
[ ... ]
> + rate_idx = cc33xx_rate_to_idx(desc->rate, status->band);
> + if (rate_idx == CONF_HW_RXTX_RATE_UNSUPPORTED)
> + dev_err(cc->dev, "Invalid RX rate from HW: %d\n", desc->rate);
> +
> + status->rate_idx = rate_idx;
[Severity: Medium]
Can passing CONF_HW_RXTX_RATE_UNSUPPORTED (0xff) in status->rate_idx trigger
warnings in mac80211?
When firmware reports an unmapped rate (such as desc->rate == 0 or a rate
above CONF_HW_RATE_INDEX_MAX), cc33xx_rx_status() logs an error but still
passes 0xff to ieee80211_rx_ni(). ieee80211_rx_list() treats an out-of-range
rate_idx as a driver bug, emitting WARN/WARN_ON/WARN_ONCE splats before
dropping the frame. Should this clamp rate_idx to a valid fallback (such as
0) or drop the frame instead?
[ ... ]
> + if (unlikely(desc_err_code & CC33XX_RX_DESC_MIC_FAIL)) {
> + status->flag |= RX_FLAG_MMIC_ERROR;
> + dev_warn(cc->dev, "Michael MIC error. Desc: 0x%x\n",
> + desc_err_code);
> + }
[Severity: Low]
Should this dev_warn(), along with the dev_err() for invalid RX rates above
and the dev_warn() for CC33XX_RX_DESC_DECRYPT_FAIL in
cc33xx_rx_get_packet_descriptor(), be ratelimited?
All three run per received packet while cc->mutex is held in
cc33xx_irq_work(). A nearby peer sending forged frames that fail decryption
or Michael MIC verification can flood the kernel log and stall operations
waiting on cc->mutex.
[ ... ]
> + /* Descriptor was fully copied */
> + pkt_data_len = cc->partial_rx.original_bytes;
> + pkt_data_len -= sizeof(struct cc33xx_rx_descriptor);
> +
> + if (unlikely(cc->partial_rx.desc.status & CC33XX_RX_DESC_DECRYPT_FAIL)) {
> + dev_warn(cc->dev, "corrupted packet in RX: status: 0x%x len: %d\n",
> + cc->partial_rx.desc.status & CC33XX_RX_DESC_STATUS_MASK,
> + pkt_data_len);
> +
> + /* If frame can be fully dropped */
> + if (pkt_data_len <= *raw_buffer_len) {
> + *raw_buffer_len -= pkt_data_len;
> + cc->partial_rx.status = CURR_RX_START;
> + } else {
> + cc->partial_rx.handled_bytes += *raw_buffer_len;
> + cc->partial_rx.status = CURR_RX_DROP;
> + *raw_buffer_len = 0;
> + }
> + goto out;
> + }
[Severity: High]
Can a malformed descriptor with desc->length < sizeof(struct
cc33xx_rx_descriptor) cause an infinite loop or an out-of-bounds read?
Without a lower-bound check on original_bytes, subtracting 16 underflows u16
pkt_data_len to 65520..65535. On the normal path this requests a ~64 KB
allocation under cc->mutex and absorbs subsequent RX traffic.
On the drop path (decrypt failure or __dev_alloc_skb() failure),
handled_bytes becomes greater than original_bytes, status becomes
CURR_RX_DROP, and *raw_buffer_len is set to 0. cc33xx_rx_handle_packet()
then immediately calls cc33xx_rx_drop_packet_data(), where signed promotion
makes (original_bytes - handled_bytes) negative:
drivers/net/wireless/ti/cc33xx/rx.c:cc33xx_rx_drop_packet_data() {
if (*raw_buffer_len >=
(cc->partial_rx.original_bytes - cc->partial_rx.handled_bytes)) {
*raw_buffer_len -= cc->partial_rx.original_bytes -
cc->partial_rx.handled_bytes;
cc->partial_rx.handled_bytes = 0;
cc->partial_rx.status = CURR_RX_START;
}
}
That increases *raw_buffer_len instead of decreasing it. Back in
cc33xx_rx(), consumed_bytes becomes 0 (looping forever while holding
cc->mutex) or underflows u16 if the descriptor was split across transfers,
advancing pkt_offset ~65 KB past cc->aggr_buf.
> + skb = __dev_alloc_skb(pkt_data_len, GFP_KERNEL);
[ ... ]
> + cc->partial_rx.skb = skb;
> + cc->partial_rx.status = CURR_RX_DATA;
[Severity: Medium]
Does cc->partial_rx.skb leak if firmware recovery or device removal happens
while a split RX frame is in CURR_RX_DATA?
cc->partial_rx.skb is never cleared to NULL after being queued to
deferred_rx_queue, and neither cc33xx_turn_off() nor cc33xx_free_hw() frees
an in-progress partial_rx.skb. Adding an RX reset helper that frees and
clears partial_rx.skb during teardown and recovery would prevent the leak.
[ ... ]
> + rx_align = cc->partial_rx.desc.header_alignment;
> + if (rx_align == CC33XX_RX_BUF_PADDED)
> + skb_pull(cc->partial_rx.skb, RX_BUF_ALIGN);
> +
> + extra_bytes = cc->partial_rx.desc.pad_len;
> + if (extra_bytes != 0)
> + skb_trim(cc->partial_rx.skb,
> + cc->partial_rx.skb->len - extra_bytes);
> +
> + hdr = (struct ieee80211_hdr *)cc->partial_rx.skb->data;
> +
> + if (ieee80211_is_beacon(hdr->frame_control))
> + beacon = 1;
> + if (ieee80211_is_probe_resp(hdr->frame_control))
> + is_probe_resp = 1;
> +
> + cc33xx_rx_status(cc, &cc->partial_rx.desc,
> + IEEE80211_SKB_RXCB(cc->partial_rx.skb),
> + beacon, is_probe_resp);
> +
> + seq_num = le16_get_bits(hdr->seq_ctrl, IEEE80211_SCTL_SEQ);
[Severity: Medium]
Can this read past skb->tail or underflow skb_trim() on short or malformed
frames?
skb_pull() and skb_trim() are called without checking that skb->len is at
least RX_BUF_ALIGN or extra_bytes; if extra_bytes > skb->len, the unsigned
subtraction wraps near UINT_MAX so skb_trim() leaves the frame untrimmed.
In addition, hdr->frame_control and hdr->seq_ctrl (offset 22..23) are read
unconditionally without checking skb->len. Any frame shorter than 24 bytes,
such as an 802.11 control frame, reads past skb->tail into uninitialized
buffer memory or skb_shared_info.
> + cc33xx_debug(cc->dev, DEBUG_RX, "rx skb 0x%p: %d B %s seq %d link id %d\n",
> + cc->partial_rx.skb,
> + cc->partial_rx.skb->len - cc->partial_rx.desc.pad_len,
> + beacon ? "beacon" : "", seq_num, cc->partial_rx.desc.hlid);
[Severity: Low]
Does this debug log subtract cc->partial_rx.desc.pad_len twice? skb_trim()
already removed extra_bytes from cc->partial_rx.skb->len just above.
> + cc33xx_debug(cc->dev, DEBUG_RX, "rx frame. frame type 0x%x, frame length 0x%x, frame address %p\n",
> + hdr->frame_control, cc->partial_rx.skb->len,
> + cc->partial_rx.skb->data);
[Severity: Low]
Should hdr->frame_control here and desc->length in cc33xx_rx_handle_packet()
be wrapped in le16_to_cpu()? Both are __le16 fields passed directly to 0x%x,
which causes sparse warnings and byte-swapped output on big-endian hosts.
> + /* Adding frame to queue */
> + skb_queue_tail(&cc->deferred_rx_queue, cc->partial_rx.skb);
> + cc->rx_counter++;
> + cc->partial_rx.status = CURR_RX_START;
> +
> + /* Make sure the deferred queues don't get too long */
> + defer_count = skb_queue_len(&cc->deferred_tx_queue);
> + defer_count += skb_queue_len(&cc->deferred_rx_queue);
> + if (defer_count >= CC33XX_RX_QUEUE_MAX_LEN)
> + cc33xx_flush_deferred_work(cc);
> + else
> + queue_work(cc->freezable_netstack_wq, &cc->netstack_work);
[Severity: High]
Can calling cc33xx_flush_deferred_work() directly here race with
cc33xx_netstack_work() and violate mac80211's RX serialization contract?
CPU0 (freezable_wq) CPU1 (freezable_netstack_wq)
cc33xx_irq_work() cc33xx_netstack_work()
guard(mutex)(&cc->mutex) cc33xx_flush_deferred_work()
cc33xx_rx() ieee80211_rx_ni()
cc33xx_rx_get_packet_data()
if (defer_count >= 256)
cc33xx_flush_deferred_work()
ieee80211_rx_ni() <-- concurrent mac80211 RX
Under heavy traffic, both workers dequeue from deferred_rx_queue and
deferred_tx_queue at the same time and call ieee80211_rx_ni() and
ieee80211_tx_status_ni() concurrently for the same ieee80211_hw. mac80211
forbids concurrent calls to these functions; doing so races on unlocked
fragment reassembly state in ieee80211_reassemble_add() (risking SKB list
corruption or out-of-bounds cache indexing) and CCMP PN replay tracking in
ieee80211_crypto_ccmp_decrypt(). Running the flush synchronously here also
holds cc->mutex across network-stack delivery, stalling hardware I/O and
mac80211 control ops.
[Severity: High]
Can this queue_work() path and cc33xx_turn_off() trigger a use-after-free on
cc->hw during device removal?
CPU0 CPU1
cc33xx_remove()
cc33xx_unregister_hw()
cc33xx_turn_off()
cc33xx_flush_deferred_work()
ieee80211_rx_ni() <-- hw already unregistered
cancel_work_sync(&netstack_work)
cc33xx_irq_work()
cc33xx_rx_get_packet_data()
queue_work(..., &netstack_work)
cancel_work_sync(&irq_deferred_work)
cc33xx_free_hw()
destroy_workqueue(freezable_netstack_wq)
cc33xx_netstack_work()
ieee80211_rx_ni() <-- use-after-free
In main.c, cc33xx_remove() calls cc33xx_unregister_hw() before
cc33xx_turn_off(), so cc33xx_flush_deferred_work() feeds frames into an
already-unregistered ieee80211_hw. Inside cc33xx_turn_off(),
cancel_work_sync(&cc->netstack_work) also runs before
cancel_work_sync(&cc->irq_deferred_work), allowing an in-flight
cc33xx_irq_work() to re-queue netstack_work after it was cancelled. Stopping
IRQs and cancelling irq_deferred_work before netstack_work, and shutting down
RX before ieee80211_unregister_hw(), would avoid both races.
[ ... ]
> + if (cc->partial_rx.status == CURR_RX_START) {
> + WARN_ON(*raw_buffer_len < 2);
> + desc = (struct cc33xx_rx_descriptor *)raw_buffer_ptr;
> + cc->partial_rx.original_bytes = le16_to_cpu(desc->length);
> + cc->partial_rx.handled_bytes = 0;
> + cc->partial_rx.status = CURR_RX_DESC;
> +
> + cc33xx_debug(cc->dev, DEBUG_RX, "rx frame. desc length 0x%x, alignment 0x%x, padding 0x%x\n",
> + desc->length, desc->header_alignment, desc->pad_len);
> + }
[Severity: Medium]
Can a split RX descriptor cause an out-of-bounds read and corrupt
cc->partial_rx.original_bytes here?
WARN_ON(*raw_buffer_len < 2) does not stop execution. If a transfer boundary
leaves 1 byte, desc->length reads 1 byte past the valid RX buffer into
partial_rx.original_bytes, and cc33xx_rx_get_packet_descriptor() never
reloads original_bytes from cc->partial_rx.desc.length after reassembly
completes, permanently desynchronizing the RX stream.
Even for larger split descriptors (*raw_buffer_len < 16), the debug print
reads desc->header_alignment and desc->pad_len (up to offset 14) past the
valid buffer when DEBUG_RX is enabled. Deferring both the length read and
the debug print until cc33xx_rx_get_packet_descriptor() finishes copying all
16 bytes would avoid reading incomplete descriptors.
[ ... ]
> +int cc33xx_rx(struct cc33xx *cc, u8 *rx_buf_ptr, u16 rx_buf_len)
> +{
> + u16 local_rx_buffer_len = rx_buf_len;
> + u16 pkt_offset = 0;
> + u16 consumed_bytes;
> + u16 prev_rx_buf_len;
> +
> + /* Split data into separate packets */
> + while (local_rx_buffer_len > 0) {
[Severity: High]
Can cc33xx_rx() read tens of kilobytes past cc->aggr_buf if
nab_rx_header->len is smaller than 8 or larger than the read transfer?
cc33xx_rx() trusts rx_buf_len directly, while its caller in main.c computes
it without bounds checking:
drivers/net/wireless/ti/cc33xx/main.c:cc33xx_irq_work() {
...
nab_rx_header = (struct nab_rx_header *)cc->aggr_buf;
rx_buf_len = le16_to_cpu(nab_rx_header->len) - 8;
if (rx_buf_len != 0) {
rx_buf_ptr = (u8 *)cc->aggr_buf + sizeof(struct nab_rx_header);
cc33xx_rx(cc, rx_buf_ptr, rx_buf_len);
...
}
If a bus glitch or hung firmware returns nab_rx_header->len < 8 (for example
0), u16 rx_buf_len underflows to 65528..65535, bypassing the rx_buf_len == 0
recovery path and causing cc33xx_rx() to parse well past the 32 KB
cc->aggr_buf allocation. The caller should validate nab_rx_header->len >= 8
and bound rx_buf_len against the actual read length and cc->aggr_buf_size.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=10
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h
2026-12-03 7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
@ 2026-12-03 7:33 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:33 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 17 potential
issues to consider:
- [High] wifi: cc33xx: uninitialized struct resource in
sdio_cc33xx_probe()
- [High] wifi: cc33xx: use-after-free before IRQ teardown in
sdio_cc33xx_remove()
- [High] wifi: cc33xx: deadlock and sleep-in-atomic in
cc33xx_sdio_disable_irq()
- [Medium] wifi: cc33xx: use-after-free before free_irq() in
sdio_cc33xx_probe()
- [Medium] wifi: cc33xx: runtime PM ref leak in cc33xx_sdio_power_on()
on error
- [Medium] wifi: cc33xx: unbalanced pm_runtime_put_noidle() on probe
failure
- [Medium] wifi: cc33xx: missing disable_irq_wake() on
sdio_cc33xx_probe() error
- [Medium] wifi: cc33xx: cc33xx_suspend() returns -EINVAL when core
driver unbound
- [Medium] wifi: cc33xx: cc33xx_probe_of() loses -EPROBE_DEFER from DT
IRQ parse
- [Medium] wifi: cc33xx: unchecked sdio_f0_readb() in
cc33xx_enable_async_interrupt()
- [Medium] wifi: cc33xx: ignored sdio_claim_irq() error in
cc33xx_sdio_enable_irq()
- [Medium] wifi: cc33xx: cc33xx_sdio_set_block_size() ignores block-size
error
- [Low] wifi: cc33xx: unprefixed global lock helpers and void* IRQ
handler
- [Low] wifi: cc33xx: prohibited linux/gpio.h include and missing
headers in sdio.c
- [Low] wifi: cc33xx: unused include of deprecated linux/gpio.h in
sdio.c
- [Low] wifi: cc33xx: local SDIO IDs and early quirk mutation in
sdio_cc33xx_probe()
- [Low] wifi: cc33xx: IRQ_NOAUTOEN flag leaked in sdio_cc33xx_probe()
--
commit a2cbcc4a1c662264be0a93163a1e9980d328c46f
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add sdio.c, io.c, io.h
This commit adds the SDIO transport driver and abstract I/O wrapper layer
for TI CC33xx wireless devices, supporting both out-of-band GPIO and
in-band SDIO interrupts.
> diff --git a/drivers/net/wireless/ti/cc33xx/io.h b/drivers/net/wireless/ti/cc33xx/io.h
> new file mode 100644
> index 0000000000000..35f6d4b483a6b
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/io.h
[ ... ]
> +void claim_core_status_lock(struct cc33xx *cc);
> +void release_core_status_lock(struct cc33xx *cc);
[Severity: Low]
Should claim_core_status_lock() and release_core_status_lock() carry the
cc33xx_ prefix used by the other helpers in io.h to avoid putting generic
names into the global symbol namespace when built into vmlinux?
Similarly, cc33xx_set_irq_handler() in sdio.c takes an untyped void *
handler and assigns it to pdev_data->irq_handler, bypassing compile-time
prototype checking instead of taking a typed function pointer.
> diff --git a/drivers/net/wireless/ti/cc33xx/sdio.c b/drivers/net/wireless/ti/cc33xx/sdio.c
> new file mode 100644
> index 0000000000000..5edbe1ebc7a80
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/sdio.c
> @@ -0,0 +1,515 @@
[ ... ]
> +#include <linux/gpio.h>
[Severity: Low]
This file does not call any GPIO APIs, and include/linux/gpio.h is
deprecated with a notice that it must not be included by new code. Can
this include be dropped?
> +#include <linux/pm_runtime.h>
> +#include <linux/of_irq.h>
> +
> +#include "cc33xx.h"
> +#include "io.h"
[Severity: Low]
In addition to the prohibited linux/gpio.h include, sdio.c includes io.h
without using any declaration from it, while relying on transitive includes
for linux/module.h, linux/mmc/card.h, linux/interrupt.h, linux/irq.h, and
linux/of.h. Adding direct includes for the APIs used here will keep this
file resilient to header cleanups.
> +
> +#ifndef SDIO_VENDOR_ID_TI
> +#define SDIO_VENDOR_ID_TI 0x0097
> +#endif
> +
> +#define SDIO_DEVICE_ID_CC33XX_NO_EFUSE 0x4076
> +#define SDIO_DEVICE_ID_TI_CC33XX 0x4077
[Severity: Low]
Should these IDs use linux/mmc/sdio_ids.h instead of local definitions?
sdio_ids.h already defines SDIO_VENDOR_ID_TI and 0x4076 as
SDIO_DEVICE_ID_TI_WL1271, so exporting 0x0097:0x4076 in cc33xx_devices[]
collides with wlcore_sdio's modalias and causes both modules to autoload on
0x0097:0x4076 hardware.
In addition, sdio_cc33xx_probe() sets MMC_QUIRK_LENIENT_FN0 and
MMC_QUIRK_BLKSZ_FOR_BYTE_MODE on the shared func->card->quirks before
cc33xx_probe_of() confirms the device matches ti,cc3300, mutating card
state even when rejecting a non-CC33xx card with -ENODEV.
[ ... ]
> +static void cc33xx_sdio_set_block_size(struct device *child,
> + unsigned int blksz)
> +{
> + struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
> + struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +
> + sdio_claim_host(func);
> + sdio_set_block_size(func, blksz);
> + sdio_release_host(func);
> +}
[Severity: Medium]
Why is the return value of sdio_set_block_size() discarded here?
When sdio_set_block_size() fails (for example with -EINVAL or an FBR write
error), func->cur_blksize is left unchanged, yet cc33xx_set_block_size() in
io.c unconditionally returns true. cc33xx_chip_wakeup() relies on a false
return to clear CC33XX_QUIRK_TX_BLOCKSIZE_ALIGN, so subsequent transfers
would use a mismatched block size.
[ ... ]
> +static int cc33xx_sdio_power_on(struct cc33xx_sdio_glue *glue)
> +{
> + int ret;
> + struct sdio_func *func = dev_to_sdio_func(glue->dev);
> + struct mmc_card *card = func->card;
> +
> + ret = pm_runtime_get_sync(&card->dev);
> + if (ret < 0) {
> + pm_runtime_put_noidle(&card->dev);
> + dev_err(glue->dev, "%s: failed to get_sync(%d)\n",
> + __func__, ret);
> +
> + return ret;
> + }
> +
> + sdio_claim_host(func);
> + ret = sdio_enable_func(func);
> + sdio_release_host(func);
> +
> + return ret;
> +}
[Severity: Medium]
Does this leak a runtime PM reference on card->dev when sdio_enable_func()
fails?
If sdio_enable_func() returns an error, cc33xx_power_on() leaves
CC33XX_FLAG_GPIO_POWER clear, so cc33xx_power_off() will not call
cc33xx_sdio_power_off() to drop the reference taken by
pm_runtime_get_sync(). Calling pm_runtime_put(&card->dev) on error (and
using pm_runtime_resume_and_get()) would keep the count balanced.
[ ... ]
> +static void cc33xx_enable_async_interrupt(struct sdio_func *func)
> +{
> + u8 reg_val;
> + const int CCCR_REG_16_ADDR = 0x16;
> + const int ENABLE_ASYNC_IRQ_BIT = BIT(1);
> +
> + reg_val = sdio_f0_readb(func, CCCR_REG_16_ADDR, NULL);
> + reg_val |= ENABLE_ASYNC_IRQ_BIT;
> + sdio_f0_writeb(func, reg_val, CCCR_REG_16_ADDR, NULL);
> +}
[Severity: Medium]
Can ignoring the error from sdio_f0_readb() corrupt CCCR register 0x16?
sdio_f0_readb() returns 0xFF on a transfer error, so without checking
err_ret a transient CMD52 read failure causes sdio_f0_writeb() to write
0xFF back to SDIO_CCCR_INTERRUPT_EXT and clobber reserved bits. This also
sets EAI without checking SDIO_INTERRUPT_EXT_SAI or updating
func->card->cccr.enable_async_irq, and duplicates SDIO_CCCR_INTERRUPT_EXT
and SDIO_INTERRUPT_EXT_EAI from linux/mmc/sdio.h.
> +
> +static void cc33xx_sdio_enable_irq(struct device *child)
> +{
> + struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
> + struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +
> + sdio_claim_host(func);
> + cc33xx_enable_async_interrupt(func);
> + sdio_claim_irq(func, inband_irq_handler);
> + sdio_release_host(func);
> +}
[Severity: Medium]
Does discarding the return value of sdio_claim_irq() hide in-band IRQ
registration failures?
If sdio_claim_irq() fails (for example with -EBUSY or an SDIO I/O error),
func->irq_handler stays NULL and the driver silently receives no in-band
interrupts until later boot or command timeouts.
> +
> +static void cc33xx_sdio_disable_irq(struct device *child)
> +{
> + struct cc33xx_sdio_glue *glue = dev_get_drvdata(child->parent);
> + struct sdio_func *func = dev_to_sdio_func(glue->dev);
> +
> + sdio_claim_host(func);
> + sdio_release_irq(func);
> + sdio_release_host(func);
> +}
[Severity: High]
Can cc33xx_sdio_disable_irq() sleep in atomic context and self-deadlock
when invoked through cc33xx_disable_interrupts_nosync()?
Unlike disable_irq_nosync() in the GPIO IRQ path, cc33xx_sdio_disable_irq()
calls sleeping sdio_claim_host() and sdio_release_irq(), which calls
kthread_stop(host->sdio_irq_thread). When an in-band SDIO IRQ arrives
while CC33XX_FLAG_SUSPENDED is set, the IRQ thread calls back into
cc33xx_sdio_disable_irq() under cc->cc_lock:
sdio_irq_thread
inband_irq_handler()
... -> cc33xx_irq()
spin_lock_irqsave(&cc->cc_lock)
cc33xx_disable_interrupts_nosync()
cc33xx_sdio_disable_irq()
sdio_claim_host() <-- sleep in atomic context
sdio_release_irq()
kthread_stop(current) <-- self-deadlock
In addition, sdio_claim_irq() and sdio_release_irq() do not provide the
nested disable-depth semantics of enable_irq() and disable_irq_nosync().
[ ... ]
> +static int cc33xx_probe_of(struct device *dev, int *irq, int *wakeirq,
> + struct cc33xx_platdev_data *pdev_data)
> +{
> + struct device_node *np = dev->of_node;
> + const struct of_device_id *of_id;
> +
> + of_id = of_match_node(cc33xx_sdio_of_match_table, np);
> + if (!of_id)
> + return -ENODEV;
> +
> + pdev_data->family = of_id->data;
> +
> + *irq = irq_of_parse_and_map(np, 0);
> +
> + *wakeirq = irq_of_parse_and_map(np, 1);
> +
> + return 0;
> +}
[Severity: Medium]
Does irq_of_parse_and_map() lose -EPROBE_DEFER when the GPIO interrupt
controller has not probed yet?
irq_of_parse_and_map() returns 0 both when the interrupts property is
omitted and when the IRQ domain is not yet registered, so
sdio_cc33xx_probe() silently falls back to sdio_ops_inband_irq instead of
deferring probe. Using of_irq_get() distinguishes -EPROBE_DEFER from an
absent interrupts property.
[ ... ]
> + /* Tell PM core that we don't need the card to be powered now */
> + pm_runtime_put_noidle(&func->dev);
> +
> + glue->core = platform_device_alloc("cc33xx", PLATFORM_DEVID_AUTO);
> + if (!glue->core) {
> + dev_err(glue->dev, "can't allocate platform_device\n");
> + return -ENOMEM;
> + }
[Severity: Medium]
Is pm_runtime_put_noidle(&func->dev) unbalanced on probe failure?
sdio_bus_probe() already calls pm_runtime_put_noidle(&func->dev) when
drv->probe() returns an error, and neither the -ENOMEM return above nor
out_dev_put restores the reference with pm_runtime_get_noresume(&func->dev).
Any failure after this point results in a double put on func->dev.
[ ... ]
> + irq_set_status_flags(gpio_irq, IRQ_NOAUTOEN);
> +
> + if (irq_flags & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW))
> + irq_flags |= IRQF_ONESHOT;
> +
> + ret = request_threaded_irq(gpio_irq, gpio_irq_hard_handler,
> + gpio_irq_thread_handler,
> + irq_flags, glue->core->name, func);
[Severity: Low]
Does calling irq_set_status_flags(gpio_irq, IRQ_NOAUTOEN) leak the
IRQ_NOAUTOEN flag on the persistent irq_desc?
Neither probe error unwind nor sdio_cc33xx_remove() clears IRQ_NOAUTOEN, so
a later consumer of that GPIO IRQ without IRQF_NO_AUTOEN would find its
interrupt left disabled. Passing IRQF_NO_AUTOEN in irq_flags to
request_threaded_irq() avoids mutating desc->status_use_accessors before
acquiring the IRQ.
[ ... ]
> + if ((mmcflags & MMC_PM_KEEP_POWER) &&
> + (enable_irq_wake(gpio_irq) == 0))
> + pdev_data->pwr_in_suspend = true;
[Severity: Medium]
Does the out_dev_put error path leak the IRQ wake reference enabled here?
free_irq() does not decrement desc->wake_depth, so if a subsequent step
such as platform_device_add() fails, out_dev_put needs to call
disable_irq_wake(pdev_data->gpio_irq_num) when pdev_data->pwr_in_suspend is
true.
[ ... ]
> + if (wakeirq > 0) {
> + res[0].start = wakeirq;
> + res[0].flags = IORESOURCE_IRQ |
> + irqd_get_trigger_type(irq_get_irq_data(wakeirq));
> + res[0].name = "wakeirq";
> +
> + ret = platform_device_add_resources(glue->core, res, 1);
[Severity: High]
Can uninitialized fields in res[0] crash platform_device_add()?
res[1] is declared on the stack without initialization and only start,
flags, and name are written, leaving end, parent, sibling, child, and desc
holding stack garbage. platform_device_add() copies res[0] and passes any
non-NULL r->parent directly to insert_resource(), dereferencing stack
garbage during probe whenever wakeirq is configured. Initializing res[0]
with DEFINE_RES_IRQ_NAMED(wakeirq, "wakeirq") (or zero-initializing res and
setting res[0].end = wakeirq) fixes this.
[ ... ]
> +out_dev_put:
> + platform_device_put(glue->core);
> +
> + if (pdev_data->gpio_irq_num)
> + free_irq(pdev_data->gpio_irq_num, func);
> +
> + return ret;
[Severity: Medium]
Can freeing glue->core before free_irq() cause a use-after-free of
action->name?
request_threaded_irq() stores glue->core->name directly in action->name
without copying it, so platform_device_put(glue->core) frees that string
while the irqaction is still visible to /proc/interrupts readers. Calling
free_irq() before platform_device_put(glue->core) closes that window.
> +static void sdio_cc33xx_remove(struct sdio_func *func)
> +{
> + struct cc33xx_sdio_glue *glue = sdio_get_drvdata(func);
> + struct platform_device *pdev = glue->core;
> + struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
> +
> + int gpio_irq_num = pdev_data->gpio_irq_num;
> + bool pwr_in_suspend = pdev_data->pwr_in_suspend;
> +
> + /* Undo decrement done above in sdio_cc33xx_probe */
> + pm_runtime_get_noresume(&func->dev);
> +
> + /* Do not use pdev_data after this point */
> + platform_device_unregister(glue->core);
> +
> + if (gpio_irq_num) {
> + free_irq(gpio_irq_num, func);
> + if (pwr_in_suspend)
> + disable_irq_wake(gpio_irq_num);
> + } else {
> + sdio_claim_host(func);
> + sdio_release_irq(func);
> + sdio_release_host(func);
> + }
> +}
[Severity: High]
Can an in-flight IRQ handler dereference freed glue->core and pdev_data
between platform_device_unregister() and free_irq() / sdio_release_irq()?
platform_device_unregister() drops the final reference and frees
glue->core, glue->core->name, and pdev_data before free_irq() or
sdio_release_irq() synchronizes and removes the IRQ handlers:
CPU0 CPU1
sdio_cc33xx_remove()
platform_device_unregister(...)
platform_device_release()
kfree(pdev_data)
kfree(glue->core)
gpio_irq_thread_handler()
dev_get_platdata(&pdev->dev)
pdev_data->irq_handler(pdev)
<-- use-after-free
free_irq(gpio_irq_num, func)
The same window also leaves action->name pointing to freed glue->core->name
for /proc/interrupts readers. Calling platform_device_del(glue->core),
then tearing down the IRQ, and finally calling
platform_device_put(glue->core) avoids both use-after-free paths.
[ ... ]
> + if (!cc) {
> + dev_err(dev, "no cc33xx module was probed\n");
> + return -EINVAL;
> + }
[Severity: Medium]
Should cc33xx_suspend() return 0 rather than -EINVAL when the child cc33xx
platform driver is not bound?
Returning -EINVAL aborts system-wide suspend whenever the separate cc33xx
module is not loaded or was unbound, even though the card can safely be
powered down (wlcore/sdio.c returns 0 in this case).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=4
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h
2026-12-03 7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
@ 2026-12-03 7:38 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:38 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [Medium] wifi: cc33xx: non-portable bitfield overlay in struct
hwinfo_bitmap
- [Medium] wifi: cc33xx: unlocked reinit_completion() race in
wait_for_boot_irq()
- [Medium] wifi: cc33xx: non-errno negative returns (-1, -2, -3) in
boot.c
- [Medium] wifi: cc33xx: slab OOB write in __cc33xx_cmd_send() on device
info response
- [Medium] wifi: cc33xx: runtime PM refcount leak in
cc33xx_sdio_power_on() on error
- [Medium] wifi: cc33xx: unlocked free-before-NULL in fw_download_free()
- [Low] wifi: cc33xx: redundant vmalloc/memcpy/vfree firmware copy in
fetch_container()
- [Low] wifi: cc33xx: missing zero-size check before vmalloc() in
fetch_container()
--
commit db57acc2ac6854560fb4bce9d60e1ec4b1b3f3c3
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add boot.c, boot.h
This commit adds the CC33xx firmware download and boot sequence in
boot.c and boot.h, loading the second-stage bootloader and main
firmware image in chunks and waiting on boot IRQs between stages.
> diff --git a/drivers/net/wireless/ti/cc33xx/boot.c b/drivers/net/wireless/ti/cc33xx/boot.c
> new file mode 100644
> index 0000000000000..4ec7c315be778
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/boot.c
[ ... ]
> +struct hwinfo_bitmap {
> + u32 disable_5g : 1u;
> + u32 disable_6g : 1u;
> + u32 disable_ble : 1u;
> + u32 disable_ble_m0plus : 1u;
> + u32 disable_m33 : 1u;
> + u64 udi : 64u;
> + u32 pg_version : 4u;
> + u32 metal_version : 4u;
> + u32 boot_rom_version : 4u;
> + u32 m3_rom_version : 4u;
> + u32 fuse_rom_structure_version : 4u;
> + u64 mac_address : 48u;
> + u32 device_part_number : 6u;
> + u32 package_type : 4u;
> + u32 fw_rollback_protection_1 : 32u;
> + u32 fw_rollback_protection_2 : 32u;
> + u32 fw_rollback_protection_3 : 32u;
> + u32 reserved : 13u;
> +} /* Aligned with boot code, must not be __packed */;
> +
> +union hw_info {
> + struct hwinfo_bitmap bitmap;
> + u8 bytes[sizeof(struct hwinfo_bitmap)];
> +};
[Severity: Medium]
Can struct hwinfo_bitmap misparse the firmware response on 32-bit or
big-endian architectures?
Because the struct is unpacked and mixes u32 and u64 bitfields, padding
before udi and mac_address depends on alignof(u64) (48 bytes on 64-bit
versus 40 bytes on i386, shifting every field after disable_m33), and
big-endian hosts lay out bitfields MSB-first without byte-swapping the
little-endian response bytes. get_device_info() then silently populates
corrupted values for cc->efuse_mac_address, cc->disable_5g, and the chip
version fields.
Describing the wire format with fixed-width __le32/__le64 fields and
decoding via le32_to_cpu()/le64_to_cpu()/FIELD_GET() would avoid ABI and
endianness dependence.
[ ... ]
> + if (container->size % 4) {
> + dev_err(cc->dev, "container size is not word-aligned: %zu\n",
> + container->size);
> + goto out;
> + }
> +
> + *container_len = container->size;
> + container_data = vmalloc(container->size);
[Severity: Low]
Can vmalloc(container->size) be called with a zero size here?
container->size % 4 passes when container->size is 0, which hits
WARN_ON_ONCE(!size) in __vmalloc_node_range_noprof(). While single-caller
request_firmware() rejects empty files, a second concurrent caller on the
batched path in _request_firmware_prepare() can wake up with
firmware->size == 0 when fw_state_done() runs for an empty .xz stream or
sysfs fallback before fw_abort_batch_reqs(). Checking !container->size
alongside container->size % 4 prevents the warning.
> + if (!container_data)
> + goto out;
> +
> + memcpy(container_data, container->data, container->size);
> +
> +out:
> + release_firmware(container);
> + return container_data;
> +}
[Severity: Low]
Is the vmalloc() and memcpy() copy of the firmware image needed here?
cc33xx_cmd_download_container_chunk() only reads from the buffer to copy
chunks into a kzalloc'd command buffer. Duplicating the image doubles
peak memory usage during boot, keeps the copy allocated across
wait_for_boot_irq(), and discards the errno from request_firmware().
Passing container->data directly to download_container() and calling
release_firmware() right after avoids the extra allocation and copy.
[ ... ]
> +static int wait_for_boot_irq(struct cc33xx *cc, u32 boot_irq_mask,
> + unsigned long timeout)
> +{
> + int ret;
> + u32 pending_irqs;
> + struct cc33xx_fw_download *fw_download;
> +
> + fw_download = cc->fw_download;
> +
> + ret = wait_for_completion_interruptible_timeout(&fw_download->wait_on_irq,
> + msecs_to_jiffies(timeout));
> +
> + /* Fetch pending IRQs while clearing them in fw_download */
> + pending_irqs = atomic_fetch_and(0, &fw_download->pending_irqs);
> + pending_irqs &= ~HINT_COMMAND_COMPLETE;
> +
> + reinit_completion(&fw_download->wait_on_irq);
[Severity: Medium]
Can reinit_completion() race with cc33xx_handle_boot_irqs() and lose a
boot IRQ wakeup?
wait_for_boot_irq() cc33xx_handle_boot_irqs()
wait_for_completion_...()
atomic_fetch_and(0, ...)
atomic_or(..., &pending_irqs)
complete(&wait_on_irq)
reinit_completion(&wait_on_irq) <-- clears done without wait.lock
reinit_completion() performs an unlocked write to done while hardware
interrupts are still enabled, so a concurrent complete() can be
overwritten and stall the next wait_for_boot_irq() for 2000 ms. If a
second boot IRQ arrives before atomic_fetch_and(), both bits are also
cleared together and the exact boot_irq_mask check fails.
Using a wait_queue_head_t with wait_event_interruptible_timeout() testing
pending_irqs avoids both the data race and the lost wakeup.
> + if (ret == 0) {
> + dev_err(cc->dev, "boot IRQ timeout\n");
> + return -1;
> + } else if (ret < 0) {
> + dev_err(cc->dev, "boot IRQ completion error %d\n", ret);
> + return -2;
> + }
> +
> + if (boot_irq_mask != pending_irqs) {
> + dev_err(cc->dev, "Unexpected IRQ received @ boot: 0x%x\n",
> + pending_irqs);
> + return -3;
> + }
[Severity: Medium]
Should wait_for_boot_irq() return standard negative errnos instead of
-1, -2, and -3?
cc33xx_init_fw() propagates these values out of probe, where they map to
-EPERM, -ENOENT, and -ESRCH instead of -ETIMEDOUT, the error from
wait_for_completion_interruptible_timeout(), and -EIO or -EPROTO.
container_download_and_wait() likewise returns -1 when fetch_container()
fails, hiding the error from request_firmware(), alignment validation,
or allocation.
[ ... ]
> +static void fw_download_free(struct cc33xx *cc)
> +{
> + if (WARN_ON(!cc->fw_download))
> + return;
> +
> + kfree(cc->fw_download);
> + cc->fw_download = NULL;
> +}
[Severity: Medium]
Can fw_download_free() race with cc33xx_handle_boot_irqs() and cause a
use-after-free or NULL pointer dereference?
cc33xx_init_fw() cc33xx_irq() / cc33xx_irq_work()
goto out; /* IRQs enabled */ process_core_status()
fw_download_free() cc33xx_handle_boot_irqs()
if (WARN_ON(!cc->fw_download))
kfree(cc->fw_download)
atomic_or(...,
&cc->fw_download->pending_irqs)
<-- use-after-free
cc->fw_download = NULL
process_core_status() invokes cc33xx_handle_boot_irqs() under
claim_core_status_lock(cc) whenever a BOOT_TIME_INTERRUPTS bit is
observed, whereas fw_download_free() takes no lock and frees
cc->fw_download before setting it to NULL. On the success path of
cc33xx_init_fw(), interrupts remain enabled when fw_download_free() runs,
and on the error path cc33xx_disable_line_irq() uses disable_irq_nosync().
Clearing cc->fw_download into a local pointer under
claim_core_status_lock(cc) before calling kfree() closes this race.
> +static int get_device_info(struct cc33xx *cc)
> +{
> + int ret;
> + union hw_info hw_info;
> + u64 mac_address;
> +
> + ret = cc33xx_cmd_get_device_info(cc, hw_info.bytes, sizeof(hw_info.bytes));
[Severity: Medium]
Can cc33xx_cmd_get_device_info() trigger a slab out-of-bounds write in
__cc33xx_cmd_send()?
cc33xx_cmd_get_device_info() allocates cmd (712 bytes) and passes
sizeof(*cmd) as res_len, while parse_control_message() accepts
device-reported lengths up to CC33XX_CMD_MAX_SIZE (896 bytes):
drivers/net/wireless/ti/cc33xx/cmd.c:__cc33xx_cmd_send() {
...
if (WARN_ON(cc->result_length > res_len)) {
dev_err(cc->dev, "Error, insufficient response buffer\n");
return -EINVAL;
}
switch (id) {
case CMD_INTERROGATE:
case CMD_DEBUG_READ:
case CMD_TEST_MODE:
case CMD_BM_READ_DEVICE_INFO:
memcpy(buf + sizeof(struct nab_header), cc->command_result,
cc->result_length);
break;
...
}
Because the bounds check compares cc->result_length against res_len
instead of res_len - sizeof(struct nab_header), a response length of
705..712 bytes writes up to 8 bytes past the end of cmd.
[ ... ]
> + ret = cc33xx_chip_wakeup(cc);
> + if (ret < 0)
> + goto power_off;
[Severity: Medium]
Does a failed cc33xx_chip_wakeup() leak a runtime PM reference on
&card->dev?
cc33xx_chip_wakeup() calls cc33xx_power_on() -> cc33xx_sdio_power_on(),
which returns an error from sdio_enable_func() without releasing the
runtime PM reference:
drivers/net/wireless/ti/cc33xx/sdio.c:cc33xx_sdio_power_on() {
...
ret = pm_runtime_get_sync(&card->dev);
if (ret < 0) {
pm_runtime_put_noidle(&card->dev);
dev_err(glue->dev, "%s: failed to get_sync(%d)\n",
__func__, ret);
return ret;
}
sdio_claim_host(func);
ret = sdio_enable_func(func);
sdio_release_host(func);
return ret;
}
Because cc33xx_power_on() only sets CC33XX_FLAG_GPIO_POWER when ret == 0,
cc33xx_power_off() at power_off: returns early without calling
cc33xx_sdio_power_off(), leaving the runtime PM usage count leaked and
preventing the SDIO card and host from runtime suspending.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=8
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h
2026-12-03 7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
@ 2026-12-03 7:42 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:42 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 21 potential
issues to consider:
- [High] wifi: cc33xx: cc->cmd_buf overflow and OOB read in
send_buffer()
- [High] wifi: cc33xx: __cc33xx_cmd_send() ignores firmware command
status
- [High] wifi: cc33xx: unchecked firmware role_id and hlid cause OOB
writes
- [High] wifi: cc33xx: unlocked result_length TOCTOU race in
__cc33xx_cmd_send()
- [Medium] wifi: cc33xx: heap buffer overflow in __cc33xx_cmd_send()
response copy
- [Medium] wifi: cc33xx: missing shift on ampdu_density in
cc33xx_cmd_add_peer()
- [Medium] wifi: cc33xx: repeated init_completion() races with late
IRQ/event complete()
- [Medium] wifi: cc33xx: missing allocated_pkts reset in clear_link and
AP role start
- [Medium] wifi: cc33xx: AP bcast_hlid total_freed_pkts not restored in
role_start_ap()
- [Medium] wifi: cc33xx: nosync IRQ disable before reboot in container
chunk download
- [Medium] wifi: cc33xx: data race on max_cmd_size in
cc33xx_set_max_buffer_size()
- [Medium] wifi: cc33xx: missing role_id validation before roc_map
bitops
- [Medium] wifi: cc33xx: unlocked roles_map and plt/state races in role
commands
- [Low] wifi: cc33xx: cc33xx_cmd_remove_peer() returns remaining jiffies
on success
- [Low] wifi: cc33xx: cc33xx_cmd_remove_peer() returns remaining jiffies
on success
- [Low] wifi: cc33xx: cc33xx_cmd_download_container_chunk() returns 1 on
success
- [Low] wifi: cc33xx: split __free(kfree) = NULL declarations and cmd
code hygiene
- [Low] wifi: cc33xx: cc33xx_cmd_roc() logs wlvif->band instead of band
on error
- [Low] wifi: cc33xx: key command buffers freed without
kfree_sensitive()
- [Low] wifi: cc33xx: unused flexible array members embedded non-last in
cmd.h headers
- [Low] wifi: cc33xx: use of bool in packed firmware struct
cc33xx_cmd_add_peer
--
commit ab9e6c5cdac7a0887cf17273eeb6a7035544d3f9
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add cmd.c, cmd.h
This commit adds the firmware command infrastructure and command definitions
for the TI CC33xx wireless driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/cmd.c b/drivers/net/wireless/ti/cc33xx/cmd.c
> new file mode 100644
> index 0000000000000..f40f467cf5178
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/cmd.c
> @@ -0,0 +1,1427 @@
[ ... ]
> +int cc33xx_set_max_buffer_size(struct cc33xx *cc, enum buffer_size max_buffer_size)
> +{
> + switch (max_buffer_size) {
> + case INI_MAX_BUFFER_SIZE:
> + /* INI FILE PAYLOAD SIZE + INI CMD PARAM + INT */
> + cc->max_cmd_size = CC33XX_INI_CMD_MAX_SIZE;
> + cc->max_cmd_size += sizeof(struct cc33xx_cmd_ini_params_download);
> + cc->max_cmd_size += sizeof(u32);
> + break;
> +
> + case CMD_MAX_BUFFER_SIZE:
> + cc->max_cmd_size = CC33XX_CMD_MAX_SIZE;
> + break;
[ ... ]
[Severity: Medium]
Can cc33xx_set_max_buffer_size() race with concurrent command sends on
cc->max_cmd_size?
cc33xx_set_max_buffer_size() updates cc->max_cmd_size in three steps without
holding cc->cmd_lock, while __cc33xx_cmd_send() checks len > cc->max_cmd_size
before taking cc->cmd_lock and send_buffer() reads it again under
cc->cmd_lock. During firmware recovery, cc33xx_recovery_work() drops
wiphy_lock and calls cc33xx_turn_off() (which zeroes cc->flags, clearing
CC33XX_FLAG_RECOVERY_IN_PROGRESS) before calling cc33xx_init_fw():
CPU0 (recovery_work) CPU1 (mac80211 / testmode)
cc33xx_recovery_work()
wiphy_unlock(...)
cc33xx_turn_off()
cc->flags = 0
cc33xx_init_fw()
cc33xx_set_max_buffer_size()
cc->max_cmd_size = ... cc33xx_op_add_interface()
cc->max_cmd_size += ... __cc33xx_cmd_send()
if (len > cc->max_cmd_size) <-- race
send_buffer()
cc->max_cmd_size += ... __ALIGN_MASK(cc->max_cmd_size, ..)
A concurrent command can observe an intermediate value or send a mismatched
transfer length to the command mailbox during firmware initialization.
Holding cc->cmd_lock around updates to cc->max_cmd_size and moving the
len > cc->max_cmd_size check under cc->cmd_lock would serialize them.
> +static int send_buffer(struct cc33xx *cc, int cmd_box_addr,
> + void *buf, size_t len)
> +{
> + size_t max_cmd_size_align;
> +
> + memcpy(cc->cmd_buf, buf, len);
> +
> + memset(cc->cmd_buf + len, 0, (CC33XX_CMD_BUFFER_SIZE) - len);
> +
> + max_cmd_size_align = __ALIGN_MASK(cc->max_cmd_size,
> + CC33XX_BUS_BLOCK_SIZE * 2 - 1);
> +
> + return cc33xx_raw_write(cc, cmd_box_addr, cc->cmd_buf,
> + max_cmd_size_align, true);
> +}
[Severity: High]
Does send_buffer() read past the end of cc->cmd_buf (and struct cc33xx) on
every firmware boot and recovery?
In drivers/net/wireless/ti/cc33xx/cc33xx.h, CC33XX_INI_CMD_MAX_SIZE already
includes CC33XX_INI_PARAM_COMMAND_SIZE (16) and sizeof(int) (4), and
cc->cmd_buf is sized to CC33XX_CMD_BUFFER_SIZE without alignment padding:
drivers/net/wireless/ti/cc33xx/cc33xx.h {
#define CC33XX_INI_CMD_MAX_SIZE (CC33X_CONF_SIZE + CC33XX_INI_PARAM_COMMAND_SIZE + sizeof(int))
#define CC33XX_CMD_BUFFER_SIZE ((CC33XX_INI_CMD_MAX_SIZE > CC33XX_CMD_MAX_SIZE)\
? CC33XX_INI_CMD_MAX_SIZE : CC33XX_CMD_MAX_SIZE)
}
Adding sizeof(struct cc33xx_cmd_ini_params_download) and sizeof(u32) again in
cc33xx_set_max_buffer_size() pushes cc->max_cmd_size 20 bytes past
sizeof(cc->cmd_buf), and __ALIGN_MASK() rounds it up by up to 255 more bytes.
cc33xx_raw_write() then reads 20 to 275 bytes past cc->cmd_buf into adjacent
slab memory during cc33xx_download_ini_params_and_wait(). In addition,
because __cc33xx_cmd_send() checks len > cc->max_cmd_size rather than
sizeof(cc->cmd_buf), any command with len > CC33XX_CMD_BUFFER_SIZE overflows
cc->cmd_buf in memcpy() and underflows the size_t length in memset().
[ ... ]
> + guard(mutex)(&cc->cmd_lock);
> +
> + init_completion(&cc->command_complete);
> + ret = send_buffer(cc, CC33XX_NAB_DATA_ADDR, buf, len);
[Severity: Medium]
Can calling init_completion(&cc->command_complete) on every command race with
a late completion from the IRQ thread?
Neither cc->command_complete nor cc->peer_remove_complete (which has the same
pattern in cc33xx_cmd_remove_peer()) is initialized in cc33xx_alloc_hw().
init_completion() reinitializes the completion's wait.lock and waitqueue
without locking, so a late completion after a timeout can corrupt them:
CPU0 (__cc33xx_cmd_send) CPU1 (threaded IRQ)
wait_for_completion_timeout() -> 0
(returns -EIO)
next __cc33xx_cmd_send() cc33xx_irq()
init_completion( parse_control_message()
&cc->command_complete) complete(&cc->command_complete)
<-- races with init_completion()
Initializing both completions once in cc33xx_alloc_hw() and using
reinit_completion() before reuse avoids reinitializing wait.lock while it may
be held.
[ ... ]
> + if (!res_len)
> + return CMD_STATUS_SUCCESS; /* Response should be discarded */
> +
> + if (WARN_ON(cc->result_length > res_len)) {
> + dev_err(cc->dev, "Error, insufficient response buffer\n");
> + return -EINVAL;
> + }
> +
> + switch (id) {
> + case CMD_INTERROGATE:
> + case CMD_DEBUG_READ:
> + case CMD_TEST_MODE:
> + case CMD_BM_READ_DEVICE_INFO:
> + memcpy(buf + sizeof(struct nab_header), cc->command_result,
> + cc->result_length);
> + break;
> + default:
> + memcpy(buf, cc->command_result, cc->result_length);
> + break;
> + }
> +
> + return CMD_STATUS_SUCCESS;
> +}
[Severity: Medium]
Can the memcpy() for CMD_INTERROGATE, CMD_DEBUG_READ, CMD_TEST_MODE, and
CMD_BM_READ_DEVICE_INFO overflow buf by up to sizeof(struct nab_header)
bytes?
Callers such as cc33xx_cmd_get_device_info() and cc33xx_cmd_test() allocate
res_len bytes and pass the full buffer size (including the leading 8-byte
struct nab_header) as res_len. Because the bounds check only tests
cc->result_length > res_len, a firmware response with
res_len - sizeof(struct nab_header) < cc->result_length <= res_len writes
past the end of buf.
[Severity: High]
Is there an unlocked double-fetch TOCTOU on cc->result_length between the
bounds check and memcpy() in __cc33xx_cmd_send()?
parse_control_message() in IRQ context writes cc->command_result (up to 896
bytes) and cc->result_length without holding cc->cmd_lock, and recovery
queued on timeout does not disable IRQs before follow-up commands can run
under wiphy_lock (for example in cc33xx_bss_erp_info_changed() or
cc33xx_start_dev()):
CPU0 (__cc33xx_cmd_send) CPU1 (threaded IRQ)
parse_control_message()
cc->result_length = small_len
complete(&cc->command_complete)
if (cc->result_length > res_len)
/* passes with small_len */
parse_control_message() [next TLV/IRQ]
memcpy(cc->command_result, ..., big)
cc->result_length = big_len
memcpy(buf, cc->command_result,
cc->result_length) <-- out-of-bounds write past buf
Without a shared lock (and a check that the response command ID matches id),
a late completion can wake a subsequent command and a concurrent IRQ update
can overwrite cc->command_result and grow cc->result_length past res_len,
overflowing small kzalloc_obj() response buffers.
[Severity: High]
Why does __cc33xx_cmd_send() unconditionally return CMD_STATUS_SUCCESS
without inspecting the firmware status in cc->command_result?
cc33xx_cmd_send_failsafe() checks the returned status against valid_rets,
which becomes dead code, and cc33xx_acx_set_ba_receiver_session() can never
detect CMD_STATUS_NO_RX_BA_SESSION. Worse, every caller of cc33xx_cmd_send()
(including CMD_SET_KEYS, CMD_ROLE_ENABLE, and CMD_ROLE_START) silently treats
firmware rejections as success and proceeds to use invalid or stale union
bytes from the response buffer.
[ ... ]
> +static int cc33xx_count_role_set_bits(unsigned long role_map)
> +{
> + int count = 0;
> + /* if device bit is set ( BIT_2 = ROLE_DEVICE)
> + * since role device is not counted
> + * remove it from map
> + */
> + role_map &= ~BIT(2);
> +
> + while (role_map != 0) {
> + count += role_map & 1;
> + role_map >>= 1;
> + }
> +
> + return count;
> +}
> +
> +int cc33xx_cmd_role_enable(struct cc33xx *cc, const u8 *addr,
> + u8 role_type, u8 *role_id)
> +{
> + int ret;
> + unsigned long role_count;
> + union cc33xx_cmd_role_enable_command *buf __free(kfree) = NULL;
[Severity: Low]
A few minor code-hygiene items in cmd.c and cmd.h:
- All 26 allocating functions in cmd.c declare __free(kfree) pointers as
"= NULL" at the top of the function and assign them later, instead of
defining and initializing them in a single statement at the allocation site.
- cc33xx_count_role_set_bits() can just use hweight_long(role_map & ~BIT(2)).
- cc333xx_cmd_role_stop_dev() has an extra "3" in its name, and
cc33xx_cmd_debug_failsafe() logs "CONFIGURE command NOK" instead of DEBUG.
- struct cc33xx_cmd_roc, cc33xx_cmd_croc, cc33xx_cmd_PLT_enable, and
cc33xx_cmd_PLT_disable omit __packed unlike sibling command structs.
[ ... ]
> + ret = cc33xx_cmd_send(cc, CMD_ROLE_ENABLE, &buf->cmd, sizeof(buf->cmd),
> + sizeof(buf->resp));
> + if (ret < 0) {
> + dev_err(cc->dev, "failed to initiate cmd role enable\n");
> + return ret;
> + }
> + __set_bit(buf->resp.role_id, cc->roles_map);
> + *role_id = buf->resp.role_id;
> +
> + return ret;
> +}
[Severity: High]
Can an unchecked firmware role_id here (and unchecked hlid values in
cc33xx_cmd_role_start_dev(), cc33xx_cmd_role_start_sta(),
cc33xx_cmd_role_start_ap(), and cc33xx_cmd_add_peer()) cause out-of-bounds
writes?
cc->roles_map holds only CC33XX_MAX_ROLES (4) bits, and cc->links[],
cc->session_ids[], and the link bitmaps hold CC33XX_MAX_LINKS (21) entries.
Because __cc33xx_cmd_send() does not check firmware status or minimum
response length, even a rejected command returning 0xff or a 4-byte
status-only response leaves an out-of-range value in buf->resp, causing
__set_bit() or cc->links[hlid] indexing to corrupt struct cc33xx and adjacent
slab memory.
> +int cc33xx_cmd_role_disable(struct cc33xx *cc, u8 *role_id)
> +{
> + struct cc33xx_cmd_role_disable *cmd __free(kfree) = NULL;
> + int ret;
> +
> + if (WARN_ON(*role_id == CC33XX_INVALID_ROLE_ID))
> + return -ENOENT;
> +
> + cmd = kzalloc_obj(*cmd);
> + if (!cmd)
> + return -ENOMEM;
> +
> + cmd->role_id = *role_id;
> +
> + ret = cc33xx_cmd_send(cc, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
> + if (ret < 0) {
> + dev_err(cc->dev, "failed to initiate cmd role disable\n");
> + return ret;
> + }
> +
> + __clear_bit(*role_id, cc->roles_map);
> + *role_id = CC33XX_INVALID_ROLE_ID;
> +
> + return ret;
> +}
[Severity: Medium]
Can concurrent calls to cc33xx_cmd_role_disable() (as well as
cc33xx_cmd_role_enable() and cc33xx_cmd_role_stop_transceiver()) race on
cc->roles_map, cc->plt_role_id, cc->plt, and cc->state?
In commit "wifi: cc33xx: Add main.c", cc33xx_unregister_hw() calls
cc33xx_plt_stop() before ieee80211_unregister_hw() without holding wiphy_lock
or cc->mutex, so it can race with NL80211_CMD_TESTMODE:
CPU0 (cc33xx_remove) CPU1 (nl80211_testmode_do)
cc33xx_unregister_hw() cc33xx_tm_cmd() [holds wiphy_lock]
cc33xx_plt_stop() cc33xx_plt_stop()
cc33xx_cmd_role_disable( cc33xx_cmd_role_disable(
cc, &cc->plt_role_id) cc, &cc->plt_role_id)
__clear_bit(*role_id, ...)
*role_id = 0xff
__clear_bit(*role_id, ...)
<-- clears bit 255 in roles_map
The second thread re-reads the overwritten *role_id (0xff) and clears bit 255
past the 4-bit cc->roles_map, corrupting cc->session_ids[]. cc->roles_map
and cc->state also race during recovery between cc33xx_turn_off() /
cc33xx_init_fw() and unlocked callers such as cc33xx_op_add_interface() or
cc33xx_plt_start().
[ ... ]
> + scoped_guard(mutex, &cc->mutex) {
> + wlvif->ap.global_hlid = buf->resp.ap.global_hlid;
> + wlvif->ap.bcast_hlid = buf->resp.ap.broadcast_hlid;
> + cc->session_ids[wlvif->ap.global_hlid] = buf->resp.ap.global_session_id;
> + cc->session_ids[wlvif->ap.bcast_hlid] = buf->resp.ap.bcast_session_id;
> + }
> +
> + cc33xx_debug(cc->dev, DEBUG_CMD, "role start: roleid=%d, global_hlid=%d, broadcast_hlid=%d, global_session_id=%d, bcast_session_id=%d, basic_rate_set: 0x%x, remote_rates: 0x%x\n",
> + wlvif->role_id,
> + buf->resp.ap.global_hlid,
> + buf->resp.ap.broadcast_hlid,
> + buf->resp.ap.global_session_id,
> + buf->resp.ap.bcast_session_id,
> + wlvif->basic_rate_set, wlvif->rate_set);
> +
> + cc33xx_set_link(cc, wlvif, wlvif->ap.global_hlid);
> + cc33xx_set_link(cc, wlvif, wlvif->ap.bcast_hlid);
[Severity: Medium]
Does cc33xx_cmd_role_start_ap() (and cc33xx_clear_link()) forget to reset
allocated_pkts for global_hlid and bcast_hlid?
Unlike cc33xx_cmd_role_start_dev(), cc33xx_cmd_role_start_sta(), and
cc33xx_cmd_add_peer(), cc33xx_cmd_role_start_ap() does not zero
cc->links[hlid].allocated_pkts, and cc33xx_clear_link() does not clear it
either. When an HLID with in-flight packets is reused after AP restart or
recovery, the stale count can never be decremented (due to the new session
ID) and can permanently throttle AP management and broadcast TX queues.
[Severity: Medium]
Should cc33xx_cmd_role_start_ap() restore
cc->links[wlvif->ap.bcast_hlid].total_freed_pkts from wlvif->total_freed_pkts?
cc33xx_clear_link() saves the broadcast link's total_freed_pkts into
wlvif->total_freed_pkts before zeroing it, and cc33xx_set_link() skips
restoring it when wlvif->bss_type == BSS_TYPE_AP_BSS. Without restoring it
here, the AP broadcast encryption PN resets to 0 across recovery or
suspend/resume, causing nonce reuse under the existing GTK and replay drops
at associated stations.
[ ... ]
> +int cc33xx_cmd_set_sta_key(struct cc33xx *cc, struct cc33xx_vif *wlvif,
> + u16 action, u8 id, u8 key_type, u8 key_size,
> + const u8 *key, const u8 *addr, u32 tx_seq_32,
> + u16 tx_seq_16)
> +{
> + struct cc33xx_cmd_set_keys *cmd __free(kfree) = NULL;
[Severity: Low]
Should cc33xx_cmd_set_sta_key() and cc33xx_cmd_set_ap_key() use
__free(kfree_sensitive) so plaintext key material copied into cmd->key is
wiped before freeing?
[ ... ]
> + if (sta->deflink.ht_cap.ht_supported) {
> + buf->cmd.ht_capabilities = cpu_to_le32(sta->deflink.ht_cap.cap);
> + buf->cmd.ht_capabilities |= cpu_to_le32(CC33XX_HT_CAP_HT_OPERATION);
> + buf->cmd.ampdu_params = sta->deflink.ht_cap.ampdu_factor |
> + sta->deflink.ht_cap.ampdu_density;
> + }
[Severity: Medium]
Is ampdu_density missing a left shift by IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT
(2) when packing buf->cmd.ampdu_params?
mac80211 stores ht_cap.ampdu_density already right-shifted by 2 bits, so
ORing it directly collides with ampdu_factor in bits 0..1 and sends a
corrupted A-MPDU Parameters byte to firmware for every HT station connecting
in AP mode.
[ ... ]
> + ret = wait_for_completion_timeout(&cc->peer_remove_complete,
> + msecs_to_jiffies(CC33XX_EVENT_TIMEOUT));
> +
> + /* If there is a timeout due to event not received, queue recovery */
> + if (!ret) {
> + ret = -ETIMEDOUT;
> + cc33xx_queue_recovery_work(cc);
> + }
> +
> + return ret;
> +}
[Severity: Low]
Does cc33xx_cmd_remove_peer() return the positive remaining jiffies count
from wait_for_completion_timeout() instead of 0 on success?
All other cc33xx_cmd_* helpers return 0 on success; setting ret = 0 when
wait_for_completion_timeout() succeeds avoids surprising callers that check
if (ret).
[ ... ]
> + default:
> + dev_err(cc->dev, "roc - unknown band: %d\n", (int)wlvif->band);
> + return -EINVAL;
> + }
[Severity: Low]
In cc33xx_cmd_roc(), this logs (int)wlvif->band instead of the band parameter
that failed the switch statement.
[ ... ]
> +int cc33xx_roc(struct cc33xx *cc, struct cc33xx_vif *wlvif, u8 role_id,
> + enum nl80211_band band, u8 channel)
> +{
> + int ret = 0;
> +
> + if (WARN_ON(test_bit(role_id, cc->roc_map)))
> + return 0;
> +
> + ret = cc33xx_cmd_roc(cc, wlvif, role_id, band, channel);
> + if (!ret)
> + __set_bit(role_id, cc->roc_map);
> +
> + return ret;
> +}
> +
> +int cc33xx_croc(struct cc33xx *cc, u8 role_id)
> +{
> + int ret = 0;
> +
> + if (WARN_ON(!test_bit(role_id, cc->roc_map)))
> + return 0;
> +
> + ret = cc33xx_cmd_croc(cc, role_id);
> + if (!ret)
> + __clear_bit(role_id, cc->roc_map);
> +
> + return ret;
> +}
[Severity: Medium]
Can cc33xx_roc(), cc33xx_croc(), and cc33xx_stop_dev() access cc->roc_map out
of bounds when role_id is CC33XX_INVALID_ROLE_ID (0xff)?
cc33xx_roc() calls test_bit(role_id, cc->roc_map) before cc33xx_cmd_roc()
checks role_id == CC33XX_INVALID_ROLE_ID, and cc33xx_croc() and
cc33xx_stop_dev() omit any role_id < CC33XX_MAX_ROLES check. During recovery
before interface reconfig, cc33xx_update_sta_state() in commit
"wifi: cc33xx: Add main.c" warns on CC33XX_INVALID_ROLE_ID without returning
and passes 0xff into cc33xx_roc() (and cc33xx_croc()), reading past the 4-bit
cc->roc_map into cc->session_ids[] and potentially clearing bit 7 of
cc->session_ids[15] in cc33xx_croc(). Validating role_id >= CC33XX_MAX_ROLES
before any roc_map bitop in all three functions prevents this.
[ ... ]
> + if (is_last_chunk) {
> + cc33xx_debug(cc->dev, DEBUG_BOOT, "Suspending IRQ while device reboots\n");
> + cc33xx_disable_interrupts_nosync(cc);
> + }
> +
> + ret = __cc33xx_cmd_send(cc, CMD_CONTAINER_DOWNLOAD, cmd,
> + command_size, sizeof(u32), is_sync_transfer);
> +
> + if (is_last_chunk) {
> + msleep(CC33XX_REBOOT_TIMEOUT_MSEC);
> + cc33xx_enable_interrupts(cc);
> + }
> +
> + return ret;
> +}
[Severity: Medium]
Can cc33xx_disable_interrupts_nosync() leave an active GPIO IRQ thread
running while the chip reboots on the final container chunk?
cc33xx_cmd_download_container_chunk() runs in sleepable context, yet calls
cc33xx_disable_interrupts_nosync() (which uses disable_irq_nosync() in GPIO
IRQ mode). Because complete(&cc->command_complete) for the previous chunk
wakes the download loop before the threaded IRQ handler finishes
process_core_status(), gpio_irq_thread_handler() can still issue SDIO
transactions while the device reboots, setting CC33XX_FLAG_IO_FAILED and
failing firmware boot. Using a synchronizing IRQ disable here would wait for
the handler to finish first.
[Severity: Low]
Does cc33xx_cmd_download_container_chunk() return CMD_STATUS_SUCCESS (1)
instead of 0 on success?
Because it calls __cc33xx_cmd_send() directly rather than cc33xx_cmd_send(),
it returns 1 instead of 0 on both synchronous and asynchronous success paths.
> diff --git a/drivers/net/wireless/ti/cc33xx/cmd.h b/drivers/net/wireless/ti/cc33xx/cmd.h
> new file mode 100644
> index 0000000000000..e58d599b84e3e
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/cmd.h
> @@ -0,0 +1,632 @@
[ ... ]
> +struct cc33xx_cmd_header {
> + struct nab_header nab_header;
> + __le16 id;
> + __le16 status;
> +
> + /* payload */
> + u8 data[];
> +} __packed;
[ ... ]
> +struct command_complete_header {
> + __le16 id;
> + __le16 status;
> +
> + /* payload */
> + u8 data[];
> +} __packed;
[Severity: Low]
Both struct cc33xx_cmd_header and struct command_complete_header declare an
unused flexible array member u8 data[] while being embedded non-last in
command and response structs, which triggers -Wflex-array-member-not-at-end
warnings. Dropping both unused data[] fields avoids the warnings.
[ ... ]
> + /* HE peer support */
> + bool has_he;
> + bool mfp;
> + u8 padding[2];
> +} __packed;
[Severity: Low]
struct cc33xx_cmd_add_peer is a __packed firmware wire-protocol struct, so
has_he and mfp should use fixed-width u8 rather than bool (matching
is_connected and wmm in the same struct and kernel coding style).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=5
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 15/17] wifi: cc33xx: Add ps.c, ps.h
[not found] ` <20261203070906.1294171-16-r-ramalingam@ti.com>
@ 2026-12-03 7:43 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:43 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] wifi: cc33xx: cc33xx_ps_set_mode() is a silent hardware no-op
--
commit b6e32d633963d12afa6bfcf6372448d5ccf79991
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add ps.c, ps.h
This commit adds ps.c and ps.h implementing cc33xx_ps_set_mode() to configure
802.11 power-save modes for the cc33xx driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/ps.c b/drivers/net/wireless/ti/cc33xx/ps.c
> new file mode 100644
> index 0000000000000..f2ed1678edb95
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/ps.c
> @@ -0,0 +1,39 @@
[ ... ]
> +int cc33xx_ps_set_mode(struct cc33xx *cc, struct cc33xx_vif *wlvif,
> + enum cc33xx_cmd_ps_mode_e mode)
> +{
> + int ret;
> + u16 timeout = cc->conf.host_conf.conn.dynamic_ps_timeout;
> +
> + switch (mode) {
> + case STATION_AUTO_PS_MODE:
> + case STATION_POWER_SAVE_MODE:
> + ret = cc33xx_cmd_ps_mode(cc, wlvif, mode, timeout);
> + if (ret < 0)
> + return ret;
> +
> + set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
> + break;
> +
> + case STATION_ACTIVE_MODE:
> + ret = cc33xx_cmd_ps_mode(cc, wlvif, mode, 0);
> + if (ret < 0)
> + return ret;
> +
> + clear_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
> + break;
[Severity: Medium]
Does cc33xx_ps_set_mode() actually change the hardware power-save state?
cc33xx_cmd_ps_mode() submits CMD_SET_PS_MODE to cc33xx_cmd_send(), but
CMD_SET_PS_MODE is defined after CMD_LAST_SUPPORTED_COMMAND in cmd.h.
cc33xx_cmd_send() checks for id >= CMD_LAST_SUPPORTED_COMMAND and returns 0
immediately without sending anything to firmware.
As a result, BSS_CHANGED_PS transitions in cc33xx_bss_info_changed_sta()
toggle WLVIF_FLAG_IN_PS and report success to mac80211 even though
cc33xx_init_ieee80211() advertises SUPPORTS_PS and SUPPORTS_DYNAMIC_PS,
leaving the firmware power-save mode unchanged.
Should this use a supported firmware command to override power-save mode, or
drop the non-functional override path and advertised power-save flags?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=15
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h
2026-12-03 7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
@ 2026-12-03 7:43 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:43 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] wifi: cc33xx: out-of-bounds read past cmd_buf during INI
download
- [High] wifi: cc33xx: target_mem_map leak and IRQ UAF on cc33xx_init()
failure
- [Medium] wifi: cc33xx: leaked partial_rx.skb on recovery reset in
cc33xx_hw_init()
- [Medium] wifi: cc33xx: unchecked cc33xx_init_phy_vif_config() return
value
- [Medium] wifi: cc33xx: missing rollback on cc33xx_init_vif_specific()
failure
- [Medium] wifi: cc33xx: unlocked max_cmd_size race during recovery INI
download
- [Medium] wifi: cc33xx: unlocked RX/TX state reset after IRQ enable in
cc33xx_hw_init()
- [Medium] wifi: cc33xx: slab OOB write in __cc33xx_cmd_send() via
cc33xx_hw_init()
- [Medium] wifi: cc33xx: big-endian double-swap of TX AC params in vif
init
- [Medium] wifi: cc33xx: leak role and rate policies if
cc33xx_init_vif_specific() fails
- [Low] wifi: cc33xx: out-of-bounds pointer arithmetic past scalar
ac_conf0 member
- [Low] wifi: cc33xx: split __free(kfree) declaration and init in INI
download
- [Low] wifi: cc33xx: write-only event_mask update in
cc33xx_init_vif_specific()
--
commit ed1928d83427e6ccca38c2d954901e5f1f86141e
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add init.c, init.h
This commit adds high-level initialization helpers for the cc33xx wireless
driver, covering per-vif firmware configuration, hardware memory map setup,
and INI parameter download.
> diff --git a/drivers/net/wireless/ti/cc33xx/init.c b/drivers/net/wireless/ti/cc33xx/init.c
> new file mode 100644
> index 0000000000000..b0d3f927ebe80
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/init.c
[ ... ]
> +int cc33xx_init_vif_specific(struct cc33xx *cc, struct ieee80211_vif *vif)
[Severity: Medium]
When cc33xx_init_vif_specific() returns an error, does the caller leak the
firmware role and rate policies allocated for this vif?
In cc33xx_op_add_interface(), cc33xx_init_vif_data() allocates bits in
cc->rate_policies_map and cc33xx_cmd_role_enable() enables the firmware role
and sets a bit in cc->roles_map before calling cc33xx_init_vif_specific().
On failure, cc33xx_op_add_interface() returns directly without disabling the
role or freeing the rate policies, and mac80211 will not call
remove_interface(). Because cc33xx_cmd_role_enable() enforces a limit of two
active non-device roles, two failed interface additions permanently exhaust
all hardware role slots until recovery or driver reload.
> +{
> + struct cc33xx_vif *wlvif = cc33xx_vif_to_data(vif);
> + struct conf_tx_settings *tx_settings = &cc->conf.host_conf.tx;
> + struct conf_tx_ac_category *conf_ac = &tx_settings->ac_conf0;
> + bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
> + u8 ps_scheme = cc->conf.mac.ps_scheme;
> + int ret, i;
> +
> + /* consider all existing roles before configuring psm. */
> +
> + if (cc->ap_count == 0 && is_ap) { /* first AP */
> + ret = cc33xx_acx_sleep_auth(cc, CC33XX_PSM_ELP);
> + if (ret < 0)
> + return ret;
> +
> + /* unmask ap events */
> + cc->event_mask |= cc->ap_event_mask;
[Severity: Medium]
If a later step in cc33xx_init_vif_specific() fails while adding the first AP
vif alongside an active STA vif, does firmware sleep_auth remain stuck at
CC33XX_PSM_ELP?
cc33xx_acx_sleep_auth() overrides the active STA sleep authorization and sets
cc->event_mask |= cc->ap_event_mask before fallible calls such as
cc33xx_init_ap_role() and cc33xx_tx_param_cfg(). Those error paths return
directly without restoring the STA sleep authorization or reverting
cc->event_mask, and because cc33xx_op_add_interface() returns without
registering the vif or incrementing cc->ap_count,
__cc33xx_op_remove_interface() never runs to undo them.
[Severity: Low]
Does updating cc->event_mask here actually unmask any AP events in firmware?
Across drivers/net/wireless/ti/cc33xx/, cc->event_mask is only written (in
cc33xx_setup(), cc33xx_init_vif_specific(), and
__cc33xx_op_remove_interface()) and is never read or sent to firmware.
process_deferred_events() dispatches events such as MAX_TX_FAILURE_EVENT_ID
directly from the firmware event vector, so cc->event_mask,
cc->ap_event_mask, and struct acx_event_mask appear to be unused leftover
code that should either be wired up to a firmware command or removed.
[ ... ]
> + cc33xx_init_phy_vif_config(cc, wlvif);
[Severity: Medium]
Should the return value of cc33xx_init_phy_vif_config() be checked here?
cc33xx_init_phy_vif_config() propagates negative errors from
cc33xx_acx_slot() (such as -ENOMEM or a firmware command failure), so
ignoring the return value leaves the vif slot time unconfigured and continues
sending subsequent ACX commands instead of failing interface setup.
> +
> + /* Default TID/AC configuration */
> + if (WARN_ON(tx_settings->ac_conf_count != tx_settings->tid_conf_count) ||
> + WARN_ON(tx_settings->ac_conf_count != CONF_TX_MAX_AC_COUNT))
> + return -EINVAL;
> +
> + for (i = 0; i < tx_settings->tid_conf_count; i++) {
> + /* If no ps poll is used, send legacy ps scheme in cmd */
> + if (ps_scheme == PS_SCHEME_NOPSPOLL)
> + ps_scheme = PS_SCHEME_LEGACY;
> +
> + ret = cc33xx_tx_param_cfg(cc, wlvif, conf_ac->ac,
> + conf_ac->cw_min, conf_ac->cw_max,
> + conf_ac->aifsn, conf_ac->tx_op_limit,
> + false, ps_scheme, conf_ac->is_mu_edca,
> + conf_ac->mu_edca_aifs,
> + conf_ac->mu_edca_ecw_min_max,
> + conf_ac->mu_edca_timer);
[Severity: Medium]
Does passing conf_ac->cw_max and conf_ac->tx_op_limit directly to
cc33xx_tx_param_cfg() double-swap them on big-endian hosts?
cc->conf stores the raw little-endian binary INI payload (copied verbatim
into cmd->payload in cc33xx_download_ini_params_and_wait()), while
cc33xx_tx_param_cfg() expects host-endian u16 arguments and encodes them with
cpu_to_le16(). On big-endian architectures, this sends byte-swapped cw_max
and tx_op_limit values in TX_PARAMS_CFG.
> +
> + if (ret < 0)
> + return ret;
> +
> + conf_ac++;
[Severity: Low]
Does incrementing conf_ac past tx_settings->ac_conf0 rely on out-of-bounds
pointer arithmetic?
In struct conf_tx_settings, ac_conf0..ac_conf3 are four separate scalar
members rather than an array, so advancing a pointer derived from
&tx_settings->ac_conf0 across CONF_TX_MAX_AC_COUNT iterations is undefined
behavior in C and can trigger -Warray-bounds or CONFIG_UBSAN_BOUNDS.
Declaring ac_conf[CONF_TX_MAX_AC_COUNT] as an array and indexing
tx_settings->ac_conf[i] avoids this.
[ ... ]
> +int cc33xx_hw_init(struct cc33xx *cc)
> +{
> + int ret;
> +
> + cc->last_fw_rls_idx = 0;
> + cc->partial_rx.status = CURR_RX_START;
[Severity: Medium]
Can resetting cc->last_fw_rls_idx and cc->partial_rx.status here race with
cc33xx_irq() and cc33xx_irq_work() because interrupts are already enabled?
cc33xx_init_fw() calls cc33xx_enable_interrupts() (which also invokes
cc33xx_irq() immediately) before calling cc33xx_hw_init(), and
cc33xx_hw_init() writes both fields without holding cc->mutex or
core_status_lock:
CPU0 CPU1 (kworker)
cc33xx_init_fw()
cc33xx_enable_interrupts()
cc33xx_irq()
queue_work(&irq_deferred_work)
cc33xx_hw_init() cc33xx_irq_work()
cc->last_fw_rls_idx = 0; mutex_lock(&cc->mutex)
cc->partial_rx.status = ... cc33xx_rx() / tx_immediate_complete()
reads partial_rx / last_fw_rls_idx
<-- data race
During hardware recovery, cc33xx_turn_off() also leaves cc->last_fw_rls_idx
non-zero, so process_core_status() immediately sees tx_result_queue_index
(0) != cc->last_fw_rls_idx after chip reset and queues irq_deferred_work.
If cc33xx_init_fw() then fails before cc33xx_hw_init(), irq_deferred_work
later runs cc33xx_tx_immediate_complete() on the powered-off chip, hits a
missing tx_frames[] entry, and re-queues recovery_work in a spurious recovery
loop. Resetting both fields before enabling interrupts avoids both issues.
[Severity: Medium]
Does unconditionally resetting cc->partial_rx.status here leak
cc->partial_rx.skb during hardware recovery?
When a multi-transfer RX frame is in progress,
cc33xx_rx_get_packet_descriptor() stores the allocated sk_buff in
cc->partial_rx.skb with status CURR_RX_DATA. If recovery triggers before the
rest of the frame arrives, neither cc33xx_turn_off() nor cc33xx_hw_init()
frees it, so the next received frame overwrites the pointer and leaks the
sk_buff. Because cc33xx_rx_get_packet_data() does not clear
cc->partial_rx.skb to NULL after queuing a completed frame, freeing it must
be guarded by status == CURR_RX_DATA (or rx.c must clear the pointer on
completion) to avoid a double free.
> +
> + ret = cc33xx_acx_init_mem_config(cc);
[Severity: High]
When probe fails after cc33xx_init_fw() succeeds, does cc33xx_init() leak
cc->target_mem_map and leave interrupts enabled against freed memory?
cc33xx_acx_init_mem_config() allocates cc->target_mem_map, which is only
freed in cc33xx_turn_off(). In cc33xx_init(), if read_version_info(),
cc33xx_init_ieee80211(), or cc33xx_register_hw() fails after
cc33xx_init_fw(), control jumps to out_irq without calling cc33xx_turn_off(),
and cc33xx_probe() then calls cc33xx_free_hw(). This leaks
cc->target_mem_map and frees cc->core_status, cc->aggr_buf, and struct cc33xx
while interrupts remain enabled and queued work (such as recovery_work queued
on read_version_info() failure) can still access them, causing a
use-after-free.
[Severity: Medium]
Can the CMD_INTERROGATE response path invoked by cc33xx_acx_init_mem_config()
write up to 8 bytes past the end of cc->target_mem_map?
cc33xx_acx_init_mem_config() passes sizeof(struct cc33xx_acx_mem_map) as
res_len to __cc33xx_cmd_send(), whose bounds check omits the leading
struct nab_header offset used by memcpy():
drivers/net/wireless/ti/cc33xx/cmd.c:__cc33xx_cmd_send() {
...
if (WARN_ON(cc->result_length > res_len)) {
...
memcpy(buf + sizeof(struct nab_header), cc->command_result,
cc->result_length);
...
}
If firmware returns a ctrl_info_length between
res_len - sizeof(struct nab_header) + 1 and res_len, the check passes and
memcpy() overflows the slab buffer by up to 8 bytes.
> +
> + return ret;
> +}
> +
> +int cc33xx_download_ini_params_and_wait(struct cc33xx *cc)
> +{
> + struct cc33xx_cmd_ini_params_download *cmd __free(kfree) = NULL;
[Severity: Low]
This isn't a bug, but kernel Cleanup API convention prefers defining and
initializing __free() variables in a single statement at the allocation site
rather than declaring them as NULL at the top of the function and assigning
them later.
[ ... ]
> + cc33xx_set_max_buffer_size(cc, INI_MAX_BUFFER_SIZE);
[Severity: Medium]
Can modifying cc->max_cmd_size outside cc->cmd_lock race with concurrent
firmware commands during hardware recovery?
During recovery, cc33xx_recovery_work() releases wiphy_lock and calls
cc33xx_turn_off(), which clears cc->flags (including
CC33XX_FLAG_RECOVERY_IN_PROGRESS) before cc33xx_init_fw() invokes
cc33xx_download_ini_params_and_wait(). Because cc33xx_op_add_interface()
does not check cc->state, a concurrent interface addition can submit commands
while cc33xx_set_max_buffer_size() updates cc->max_cmd_size in three unlocked
stores:
CPU0 (recovery_work) CPU1 (nl80211)
cc33xx_turn_off()
cc->flags = 0;
cc33xx_init_fw()
cc33xx_download_ini_params_and_wait()
cc33xx_set_max_buffer_size() cc33xx_op_add_interface()
cc->max_cmd_size = ... ...
cc->max_cmd_size += ... __cc33xx_cmd_send()
reads cc->max_cmd_size
<-- data race
Concurrent command submissions can observe a torn intermediate value or the
elevated INI_MAX_BUFFER_SIZE transfer length and disrupt the firmware command
protocol.
> +
> + cmd->length = cpu_to_le32(sizeof(cc->conf));
> +
> + /* copy INI file params payload */
> + memcpy((cmd->payload), &cc->conf, sizeof(cc->conf));
> +
> + ret = cc33xx_cmd_send(cc, CMD_DOWNLOAD_INI_PARAMS,
> + cmd, command_size, 0);
[Severity: High]
Does sending CMD_DOWNLOAD_INI_PARAMS with INI_MAX_BUFFER_SIZE read out of
bounds past cc->cmd_buf and the end of struct cc33xx?
In cc33xx.h, CC33XX_INI_CMD_MAX_SIZE already includes the 16-byte command
header and 4-byte int, and cc->cmd_buf is sized to CC33XX_CMD_BUFFER_SIZE
(which equals CC33XX_INI_CMD_MAX_SIZE because sizeof(cc->conf) exceeds 896
bytes). However, cc33xx_set_max_buffer_size() adds those 20 bytes a second
time, and send_buffer() aligns cc->max_cmd_size up to a 256-byte boundary
before passing cc->cmd_buf to cc33xx_raw_write():
drivers/net/wireless/ti/cc33xx/cmd.c:cc33xx_set_max_buffer_size() {
...
case INI_MAX_BUFFER_SIZE:
cc->max_cmd_size = CC33XX_INI_CMD_MAX_SIZE;
cc->max_cmd_size += sizeof(struct cc33xx_cmd_ini_params_download);
cc->max_cmd_size += sizeof(u32);
break;
...
}
drivers/net/wireless/ti/cc33xx/cmd.c:send_buffer() {
...
max_cmd_size_align = __ALIGN_MASK(cc->max_cmd_size,
CC33XX_BUS_BLOCK_SIZE * 2 - 1);
return cc33xx_raw_write(cc, cmd_box_addr, cc->cmd_buf,
max_cmd_size_align, true);
}
This reads 20 to 275 bytes past cc->cmd_buf and past the trailing fields of
struct cc33xx on every firmware initialization and recovery, triggering KASAN
slab-out-of-bounds faults and transmitting adjacent kernel heap memory over
SDIO. Additionally, cc->cmd_buf is embedded in struct cc33xx without DMA
cache-line alignment while passed to sdio_writesb(), sharing cache lines with
adjacent fields such as dynamic_fw_traces and extra_spare_key_count.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=12
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 17/17] wifi: cc33xx: Add Kconfig, Makefile
[not found] ` <20261203070906.1294171-18-r-ramalingam@ti.com>
@ 2026-12-03 7:46 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:46 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] wifi: cc33xx: inaccurate Kconfig help text copied from wlcore
- [Low] wifi: cc33xx: missing MAINTAINERS entry leaves new driver
orphaned
--
commit 11a66065130bacaec541426cb1ff81d467c463be
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add Kconfig, Makefile
This commit adds the Kconfig and Makefile for the cc33xx wireless driver and
wires them into drivers/net/wireless/ti/.
> diff --git a/drivers/net/wireless/ti/Makefile b/drivers/net/wireless/ti/Makefile
> index 05ee016594f8c..4356f58b4b989 100644
> --- a/drivers/net/wireless/ti/Makefile
> +++ b/drivers/net/wireless/ti/Makefile
> @@ -3,3 +3,4 @@ obj-$(CONFIG_WLCORE) += wlcore/
> obj-$(CONFIG_WL12XX) += wl12xx/
> obj-$(CONFIG_WL1251) += wl1251/
> obj-$(CONFIG_WL18XX) += wl18xx/
> +obj-$(CONFIG_CC33XX) += cc33xx/
[Severity: Low]
Should this series also add a MAINTAINERS entry for cc33xx?
Because MAINTAINERS has no entry for cc33xx, the wildcard
"F: drivers/net/wireless/ti/" under TI WILINK WIRELESS DRIVERS leaves
drivers/net/wireless/ti/cc33xx/ marked Orphan with no maintainer, and
Documentation/devicetree/bindings/net/wireless/ti,cc33xx.yaml uncovered.
Adding a dedicated MAINTAINERS section for cc33xx covering the driver and
devicetree binding, together with an "X: drivers/net/wireless/ti/cc33xx/"
exclusion under TI WILINK WIRELESS DRIVERS, would ensure get_maintainer.pl
routes patches properly.
> diff --git a/drivers/net/wireless/ti/cc33xx/Kconfig b/drivers/net/wireless/ti/cc33xx/Kconfig
> new file mode 100644
> index 0000000000000..3296201ef7c15
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/Kconfig
> @@ -0,0 +1,24 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +config CC33XX
> + tristate "TI CC33XX support"
> + depends on MAC80211
> + select FW_LOADER
> + help
> + This module contains the main code for TI CC33XX WLAN chips. It abstracts
> + hardware-specific differences among different chipset families.
> + Each chipset family needs to implement its own lower-level module
> + that will depend on this module for the common code.
> +
> + If you choose to build a module, it will be called cc33xx. Say N if
> + unsure.
[Severity: Low]
Does this help text accurately describe the cc33xx module architecture?
The text is copied from drivers/net/wireless/ti/wlcore/Kconfig, where wlcore
exports symbols for separate chipset-family modules. Unlike wlcore, cc33xx
exports no symbols and implements the platform driver directly, relying on
CC33XX_SDIO to instantiate the platform device in sdio_cc33xx_probe().
Users configuring the kernel may enable CONFIG_CC33XX without
CONFIG_CC33XX_SDIO and end up with a driver that cannot bind to hardware.
Rewriting the help text to describe the cc33xx core driver and mention that
CC33XX_SDIO is required would avoid confusion.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=17
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h
2026-12-03 7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
@ 2026-12-03 7:47 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:47 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 20 potential
issues to consider:
- [High] wifi: cc33xx: IEEE80211_HT_CTL_LEN TX gap never stripped on
completion/reset
- [High] wifi: cc33xx: missing ieee80211_tx_info_clear_status() corrupts
TX status
- [High] wifi: cc33xx: netstack_work queued on freezable_wq instead of
netstack wq
- [High] wifi: cc33xx: cc33xx_send_tx_pending_pkts() misses TX_PENDING
flag
- [High] wifi: cc33xx: unlocked core_status->fw_info reads race with IRQ
DMA
- [High] wifi: cc33xx: use-after-free of RCU info->control.hw_key in TX
path
- [High] wifi: cc33xx: cc33xx_tx_complete_packet() never increments
total_freed_pkts
- [Medium] wifi: cc33xx: SKB leaked on cc33xx_tx_buf_write() error in
-EAGAIN path
- [Medium] wifi: cc33xx: cc33xx_tx_reset() leaks per-link allocated_pkts
in AP mode
- [Medium] wifi: cc33xx: lost TX wakeups across wake_queues(),
complete(), wake_txq
- [Medium] wifi: cc33xx: cc33xx_wake_queues() wakes queues while stop
reasons hold
- [Medium] wifi: cc33xx: TX work fragments SDIO writes and redundantly
zeroes aggr_buf
- [Medium] wifi: cc33xx: cc33xx_send_tx_pending_pkts() nests prio loop
inside hlid loop
- [Medium] wifi: cc33xx: infinite -EAGAIN loop in cc33xx_tx_allocate()
callers
- [Medium] wifi: cc33xx: cc33xx_tx_reset() leaves last_fw_rls_idx stale
across recovery
- [Medium] wifi: cc33xx: cc33xx_send_txq_pkts() drops aggr_buf on
invalid hlid
- [Low] wifi: cc33xx: commit message cites nonexistent
cc33xx_tx_work_locked()
- [Low] wifi: cc33xx: cc33xx_tx_immediate_complete() overwrites error
ret in loop
- [Low] wifi: cc33xx: cc33xx_send_txq_pkts() takes cc_lock per packet to
check queue
- [Low] wifi: cc33xx: cc33xx_tx_flush() polls with msleep(20) under
wiphy lock
--
commit f12741bd53441412dcd5a8c8fd7b196d2953e3dd
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add tx.c, tx.h
This commit adds the TX path for the cc33xx wireless driver, including
frame preparation, aggregation, queue management, and TX completion
handling.
> or from the deferred IRQ context (irq_deferred_work). Both trigger
> cc->tx_work (cc33xx_tx_work @ tx.c) which will call
> cc33xx_tx_work_locked where data from MAC80211 SKBs will be packed
> and transferred to HW.
[Severity: Low]
This isn't a bug, but cc33xx_tx_work() actually calls cc33xx_do_tx_work(),
and there is no cc33xx_tx_work_locked() in the driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/tx.c b/drivers/net/wireless/ti/cc33xx/tx.c
> new file mode 100644
> index 0000000000000..a616afd5ad3fa
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/tx.c
[ ... ]
> +static int cc33xx_tx_allocate(struct cc33xx *cc, struct sk_buff *skb,
> + u32 extra, u32 buf_offset, u8 hlid,
> + struct nab_tx_header *nab_cmd)
> +{
> + struct cc33xx_tx_hw_descr *desc;
> + u32 total_blocks;
> + int id, ret = -EBUSY, ac;
> + u32 spare_blocks;
> + u32 total_skb_len = skb->len + extra;
> + /* Add NAB command required for CC33xx architecture */
> + u32 total_len = sizeof(struct nab_tx_header);
> +
> + total_skb_len += sizeof(struct cc33xx_tx_hw_descr);
> + total_len += total_skb_len;
> +
> + cc33xx_debug(cc->dev, DEBUG_TX, "cc->tx_blocks_available %d\n",
> + cc->tx_blocks_available);
> +
> + if (buf_offset + total_len > cc->aggr_buf_size)
> + return -EAGAIN;
[Severity: Medium]
Can this cause an infinite loop if a single frame exceeds cc->aggr_buf_size?
When buf_offset is already 0 and total_len > cc->aggr_buf_size, returning
-EAGAIN makes cc33xx_send_txq_pkts() and cc33xx_send_tx_pending_pkts() call
cc33xx_tx_buf_write(cc, 0) (which returns 0 immediately) and jump back to
try_again forever while holding cc->mutex, hanging the worker and wedging
the driver. Because mac80211 enables software monitor interfaces with an
uncapped max_mtu, an injected frame larger than 32 KB can reach this path.
Returning a fatal error such as -EMSGSIZE when total_len > cc->aggr_buf_size
would let callers drop the skb instead of retrying.
[ ... ]
> +static bool cc33xx_lnk_high_prio(struct cc33xx *cc, u8 hlid,
> + struct cc33xx_link *lnk)
> +{
> + u8 thold;
> + struct core_fw_status *core_fw_status = &cc->core_status->fw_info;
> + unsigned long suspend_bitmap, fast_bitmap, ps_bitmap;
> +
> + suspend_bitmap = le32_to_cpu(core_fw_status->link_suspend_bitmap);
> + fast_bitmap = le32_to_cpu(core_fw_status->link_fast_bitmap);
> + ps_bitmap = le32_to_cpu(core_fw_status->link_ps_bitmap);
[Severity: High]
Can these reads of cc->core_status->fw_info race with IRQ DMA?
CPU0 (cc33xx_do_tx_work) CPU1 (cc33xx_irq)
mutex_lock(&cc->mutex) claim_core_status_lock(cc)
... read_core_status(cc, cc->core_status)
cc33xx_lnk_high_prio() /* SDIO/SPI DMA into core_status */
read core_status->fw_info process_core_status()
<-- data race / DMA hazard memcpy/memset(cc->core_status, ...)
cc33xx_lnk_high_prio() and cc33xx_lnk_low_prio() only hold cc->mutex,
whereas cc33xx_irq() updates cc->core_status under claim_core_status_lock().
Reading cc->core_status during an active bus DMA transfer violates DMA
buffer ownership on non-coherent ARM/ARM64 SoCs and can corrupt adjacent
core_status fields or return torn/zeroed flow-control bitmaps.
Taking claim_core_status_lock() (as cc33xx_tx_immediate_complete() does) or
snapshotting fw_info under that lock would avoid the race.
[ ... ]
> +static int cc33xx_send_txq_pkts(struct cc33xx *cc, int qid, bool low_prio_tx)
> +{
> + struct cc33xx_vif *wlvif = NULL;
> + struct cc33xx_link *lnk = NULL;
> + struct ieee80211_txq *txq = NULL;
> + u8 hlid = CC33XX_INVALID_LINK_ID;
> + struct sk_buff *skb = NULL;
> + u32 buf_offset = 0;
> + int ac = CONF_TX_AC_BE;
> + int ret = 0;
> + bool tx_allowed = true;
> +
> + memset(cc->aggr_buf, 0, 0x300);
[Severity: Medium]
Is this memset() needed, and does resetting buf_offset per call fragment
SDIO writes?
cc33xx_do_tx_work() calls cc33xx_send_tx_pending_pkts() once and
cc33xx_send_txq_pkts() eight times (four ACs across two priority passes).
Because each call keeps a local buf_offset and flushes via
cc33xx_tx_buf_write(), a single TX batch splits into up to nine separate
SDIO transactions (each claiming the host and padding to 256 bytes), and
memset(cc->aggr_buf, 0, 0x300) unconditionally zeroes 6 KB per run even
when queues are empty, despite cc33xx_prepare_tx_frame() and
cc33xx_tx_buf_write() overwriting every transmitted byte.
Passing a shared buf_offset through cc33xx_do_tx_work() and dropping the
memset() would allow aggregating across ACs and priority passes in one bus
write.
> + while ((txq = ieee80211_next_txq(cc->hw, qid))) {
> + ac = cc33xx_tx_get_queue(txq->ac);
> + wlvif = cc33xx_vif_to_data(txq->vif);
> + hlid = cc33xx_tx_get_hlid(cc, wlvif, NULL, txq->sta);
> +
> + /* hlid invalid. Shouldn't happen */
> + if (WARN_ON_ONCE(hlid == CC33XX_INVALID_LINK_ID)) {
> + ieee80211_return_txq(cc->hw, txq, false);
> + return -EINVAL;
> + }
[Severity: Medium]
Does returning -EINVAL here strand frames already prepared into
cc->aggr_buf from earlier TXQs?
For each earlier frame, cc33xx_tx_allocate() already reserved a slot in
cc->tx_frames[] and decremented cc->tx_blocks_available, so returning
without calling cc33xx_tx_buf_write(cc, buf_offset) means firmware never
sees those frames or sends TX completions. When cc33xx_do_tx_work() is
called from cc33xx_stop_dev(), none of its callers queue recovery on error,
leaving those skbs and TX descriptors leaked until an unrelated reset. In
a multi-interface setup, this can be reached if cc33xx_bss_info_changed_ap()
clears wlvif->ap.bcast_hlid before clearing WLVIF_FLAG_AP_STARTED, or if
cc33xx_join() fails during STA connection.
Flushing cc->aggr_buf (or skipping the invalid TXQ instead of aborting the
batch) would avoid stranding already-allocated descriptors.
> + lnk = &cc->links[hlid];
> + while (!cc33xx_is_queue_stopped(cc, wlvif, ac)) {
[Severity: Low]
Does cc33xx_is_queue_stopped() need to disable IRQs and take cc->cc_lock on
every packet?
All writers to cc->queue_stop_reasons[] already use atomic bit operations,
and cc33xx_is_queue_stopped() drops cc->cc_lock immediately after reading
the word, so the lock provides no mutual exclusion with the loop body while
adding contention against cc33xx_op_tx(). A lockless READ_ONCE() of
cc->queue_stop_reasons[hwq] would suffice here.
[ ... ]
> + rcu_read_lock();
> + skb = ieee80211_tx_dequeue_ni(cc->hw, txq);
> + rcu_read_unlock();
> +
> + if (!skb)
> + break;
> +
> +try_again:
> + ret = cc33xx_prepare_tx_frame(cc, wlvif, skb, buf_offset, hlid);
[Severity: High]
Can releasing rcu_read_lock() before cc33xx_prepare_tx_frame() cause a
use-after-free of info->control.hw_key?
CPU0 (cc33xx_send_txq_pkts) CPU1 (key removal / rekey)
rcu_read_lock()
skb = ieee80211_tx_dequeue_ni()
rcu_read_unlock()
ieee80211_key_free()
synchronize_net()
kfree_sensitive(key)
cc33xx_prepare_tx_frame()
info->control.hw_key->cipher <-- use-after-free
Pointers in skb->cb such as info->control.hw_key are RCU-protected with no
reference count, so mac80211 frees the key right after synchronize_net().
The same use-after-free applies to skbs queued on cc->links[hlid].tx_pending
(from cc33xx_op_tx() or the -EBUSY fallback) and later passed to
cc33xx_prepare_tx_frame() in cc33xx_send_tx_pending_pkts().
> + if (ret == -EAGAIN) {
> + /* Aggregation buffer is full.
> + * Flush buffer and try again.
> + */
> + ret = cc33xx_tx_buf_write(cc, buf_offset);
> + if (ret < 0) {
> + ieee80211_return_txq(cc->hw, txq, false);
> + return ret;
> + }
[Severity: Medium]
Does this error path leak skb when cc33xx_tx_buf_write() fails?
When cc33xx_prepare_tx_frame() returns -EAGAIN, skb has already been
dequeued but not yet inserted into cc->tx_frames[], so returning here drops
the last reference and even cc33xx_tx_reset() cannot reclaim it. The same
leak occurs in cc33xx_send_tx_pending_pkts() on its -EAGAIN flush error
path.
[ ... ]
> +static int cc33xx_send_tx_pending_pkts(struct cc33xx *cc)
> +{
> + struct sk_buff *skb = NULL;
> + int hlid = CC33XX_INVALID_LINK_ID;
> + struct cc33xx_link *lnk = NULL;
> + u32 buf_offset = 0;
> + struct cc33xx_vif *wlvif = NULL;
> + int ret = 0;
> + bool tx_allowed = true;
> +
> + for (hlid = 0; hlid < CC33XX_MAX_LINKS; hlid++) {
> + if (!test_bit(hlid, cc->links_map))
> + continue;
> +
> + lnk = &cc->links[hlid];
> +
> + /* First try high prio link, next consider high or low prio link. */
> + for (int prio = 0; prio < 2; prio++) {
[Severity: Medium]
Should the prio loop be outside the hlid loop?
With prio nested inside hlid, a lower HLID consumes both its high-priority
and low-priority quotas before higher HLIDs are visited at all. If firmware
TX buffers fill during prio == 1 (-EBUSY), the function returns early and
starves higher HLIDs even of their high-priority quota.
[ ... ]
> + if (!tx_allowed) {
> + skb_queue_head(&cc->links[hlid].tx_pending, skb);
> + break;
> + }
[Severity: High]
Should CC33XX_FLAG_TX_PENDING be set here before breaking?
cc33xx_do_tx_work() clears CC33XX_FLAG_TX_PENDING on entry. When a link
hits its per-link threshold while global TX blocks are still available
(CC33XX_FLAG_FW_TX_BUSY clear), leaving CC33XX_FLAG_TX_PENDING unset means
cc33xx_tx_immediate_complete() will not re-queue cc->tx_work once in-flight
frames finish, stalling the remaining tx_pending frames (such as RoC or
management frames) until an unrelated TX arrives.
[ ... ]
> +/* caller must hold cc->mutex and TX must be stopped */
> +void cc33xx_tx_reset(struct cc33xx *cc)
> +{
> + int i;
> + struct sk_buff *skb;
> + struct ieee80211_tx_info *info;
[Severity: Medium]
Does cc33xx_tx_reset() leave cc->links[hlid].allocated_pkts inflated?
In-flight frames freed from cc->tx_frames[] here never decrement
allocated_pkts, and neither cc33xx_clear_link() nor
cc33xx_cmd_role_start_ap() resets it (cc33xx_turn_off() only zeroes
CC33XX_SYSTEM_HLID). After recovery or an AP restart while frames were in
flight, stale counts survive on wlvif->ap.global_hlid and
wlvif->ap.bcast_hlid, shrinking or blocking their TX flow-control window.
[ ... ]
> + for (i = 0; i < CC33XX_NUM_TX_DESCRIPTORS; i++) {
> + if (!cc->tx_frames[i])
> + continue;
> +
> + skb = cc->tx_frames[i];
> + cc33xx_free_tx_id(cc, i);
[Severity: Medium]
Should cc33xx_tx_reset() also reset cc->last_fw_rls_idx to 0?
Commit "wifi: cc33xx: Add init.c, init.h" resets cc->last_fw_rls_idx in
cc33xx_hw_init(), but cc33xx_init_fw() enables interrupts before calling
cc33xx_hw_init(). If recovery fails during firmware download after IRQs
are enabled, process_core_status() sees tx_result_queue_index (0) differ
from the stale non-zero last_fw_rls_idx and queues irq_deferred_work. Once
recovery exits, cc33xx_tx_immediate_complete() walks up to 107 stale ring
entries against the emptied cc->tx_frames[], flooding logs and queueing
another recovery on the powered-off device.
[ ... ]
> + while (!time_after(jiffies, timeout)) {
> + cc33xx_debug(cc->dev, DEBUG_MAC80211, "flushing tx buffer: %d %d\n",
> + cc->tx_frames_cnt,
> + cc33xx_tx_total_queue_count(cc));
> +
> + /* force Tx and give the driver some time to flush data */
> + mutex_unlock(&cc->mutex);
> + if (cc33xx_tx_total_queue_count(cc))
> + cc33xx_tx_work(&cc->tx_work);
> + msleep(20);
> + mutex_lock(&cc->mutex);
[Severity: Low]
Can this msleep(20) polling loop be replaced with a waitqueue or
completion?
Whenever any frame is in flight or pending, this unconditionally sleeps at
least 20 ms with all TX queues stopped and the wiphy lock held, adding
latency to scans, channel switches, and key updates even if the frame
completes in under a millisecond.
[ ... ]
> + /* mark all possible queues as awake */
> + for (i = 0; i < CC33XX_NUM_MAC_ADDRESSES * NUM_TX_QUEUES; i++) {
> + WARN_ON_ONCE(!test_and_clear_bit(reason,
> + &cc->queue_stop_reasons[i]));
> + }
> +
> + /* use the global version to make sure all vifs in mac80211 we don't
> + * know are woken up.
> + */
> + ieee80211_wake_queues(cc->hw);
[Severity: Medium]
Can cc33xx_wake_queues() resume TX while another stop reason is still
active?
When configuring a TKIP key, cc33xx_op_set_key() stops queues with
CC33XX_QUEUE_STOP_REASON_SPARE_BLK and then calls cc33xx_tx_flush(), which
stops and wakes queues with CC33XX_QUEUE_STOP_REASON_FLUSH. Because
cc33xx_wake_queues() never checks whether other bits remain set in
cc->queue_stop_reasons[], it unconditionally calls ieee80211_wake_queues(),
clears CC33XX_FLAG_TX_STOPPED, and schedules cc->tx_work before
cc33xx_hw_set_key() updates the firmware key and spare-block count.
> + clear_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags);
> +
> + if (!test_bit(CC33XX_FLAG_FW_TX_BUSY, &cc->flags) &&
> + test_bit(CC33XX_FLAG_TX_PENDING, &cc->flags))
> + ieee80211_queue_work(cc->hw, &cc->tx_work);
[Severity: Medium]
Can unsynchronized flag checks across cc33xx_wake_queues(),
cc33xx_handle_wake_tx_queue(), and cc33xx_tx_immediate_complete() lose a
TX wakeup?
CPU0 (cc33xx_handle_wake_tx_queue) CPU1 (cc33xx_wake_queues)
ieee80211_wake_queues()
test_bit(TX_STOPPED) -> 1
clear_bit(TX_STOPPED)
test_bit(TX_PENDING) -> 0
return (no tx_work queued)
set_bit(TX_PENDING) <-- wakeup lost
cc33xx_handle_wake_tx_queue() checks CC33XX_FLAG_TX_STOPPED and
CC33XX_FLAG_FW_TX_BUSY without cc->cc_lock, and cc33xx_wake_queues() calls
ieee80211_wake_queues() before clearing CC33XX_FLAG_TX_STOPPED. A similar
lost wakeup occurs if cc33xx_tx_immediate_complete() clears
CC33XX_FLAG_FW_TX_BUSY while CC33XX_FLAG_TX_STOPPED is set: it skips
queueing tx_work without setting CC33XX_FLAG_TX_PENDING, so the subsequent
cc33xx_wake_queues() does not schedule tx_work either.
[ ... ]
> + /* update the TX status info */
> + if (tx_success && !(info->flags & IEEE80211_TX_CTL_NO_ACK))
> + info->flags |= IEEE80211_TX_STAT_ACK;
> +
> + info->status.rates[0].count = 1; /* no data about retries */
> + info->status.ack_signal = -1;
[Severity: High]
Does omitting ieee80211_tx_info_clear_status(info) leave unioned control
fields in info->status?
In struct ieee80211_tx_info, control.jiffies aliases status.rates[] and
control.vif aliases status.tx_time, status.flags, and status.link_valid.
Because cc33xx sets IEEE80211_HW_HAS_RATE_CONTROL, PS-buffered or filtered
frames retain raw jiffies bytes in status.rates[0].idx, which causes
sta_set_rate_info_tx() to read past sband->bitrates[] out of bounds when
station bitrate is queried. On 64-bit kernels, canonical pointer bytes in
control.vif also set IEEE80211_TX_STATUS_ACK_SIGNAL_VALID and corrupt
status.tx_time on every completed frame.
Calling ieee80211_tx_info_clear_status(info) after inspecting
info->control.hw_key (and in cc33xx_tx_reset() and
cc33xx_tx_reset_link_queues()) would clear the aliased fields.
[ ... ]
> + /* remove private header from packet */
> + skb_pull(skb, sizeof(struct cc33xx_tx_hw_descr));
> +
> + /* remove TKIP header space if present */
> + if ((cc->quirks & CC33XX_QUIRK_TKIP_HEADER_SPACE) &&
> + info->control.hw_key &&
> + info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
> + int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
> +
> + memmove(skb->data + CC33XX_EXTRA_SPACE_TKIP, skb->data, hdrlen);
> + skb_pull(skb, CC33XX_EXTRA_SPACE_TKIP);
> + }
[Severity: High]
Does this leave the unconditional 4-byte IEEE80211_HT_CTL_LEN gap inside
every completed skb?
cc33xx_prepare_tx_frame() unconditionally adds IEEE80211_HT_CTL_LEN to
extra, and cc33xx_tx_fill_hdr() shifts the 802.11 header backward by extra
bytes (and shifts skb->network_header forward by extra). Neither
cc33xx_tx_complete_packet() nor cc33xx_tx_reset() collapses and pulls that
4-byte gap before returning the skb to mac80211, corrupting management TX
status reports, failed BAR parsing, and monitor captures; if mac80211
re-queues a filtered frame, each round-trip also leaks 4 bytes of headroom
and can trigger skb_under_panic().
[ ... ]
> + /* per link */
> + desc_session_idx = le16_get_bits(tx_desc->tx_attr, CC33XX_TX_HW_ATTR_SESSION_COUNTER);
> +
> + if (cc->session_ids[tx_desc->hlid] == desc_session_idx)
> + cc->links[tx_desc->hlid].allocated_pkts--;
[Severity: High]
Should cc->links[tx_desc->hlid].total_freed_pkts be incremented here?
cc33xx_set_key() seeds firmware hardware encryption PN/TSC from
cc->links[hlid].total_freed_pkts when reinstalling keys after suspend or
recovery, but total_freed_pkts is never incremented anywhere in the driver.
As a result, suspend/resume resets the PN to 0 (and recovery only adds 255),
causing cryptographic nonce reuse under the same CCMP/GCMP/TKIP key and
peer replay-protection drops.
[ ... ]
> + /* return the packet to the stack */
> + skb_queue_tail(&cc->deferred_tx_queue, skb);
> + queue_work(cc->freezable_wq, &cc->netstack_work);
[Severity: High]
Should cc->netstack_work be queued on cc->freezable_netstack_wq instead of
cc->freezable_wq?
The RX path in cc33xx_rx_get_packet_data() queues cc->netstack_work on
cc->freezable_netstack_wq. Queueing the same work_struct on two different
workqueues breaks workqueue non-reentrancy, allowing concurrent execution
of cc33xx_netstack_work() (reordering RX skbs), defeating
cancel_work_sync(&cc->netstack_work) in cc33xx_turn_off() (risking a
use-after-free during teardown), and stalling irq_deferred_work on the
max_active=1 cc->freezable_wq.
[ ... ]
> + for (i = cc->last_fw_rls_idx; i != tx_result_queue_index;
> + i = (i + 1) % CC33XX_TX_RESULT_QUEUE_SIZE) {
> + ret = cc33xx_tx_complete_packet(cc, core_fw_status.tx_result_queue[i],
> + &core_fw_status);
> + }
> +
> + cc->last_fw_rls_idx = tx_result_queue_index;
> +
> + /* if new mem blocks available and tx was busy or pending,
> + * queue the tx work.
> + */
> + if (!ret && !test_bit(CC33XX_FLAG_TX_STOPPED, &cc->flags) &&
> + (tx_busy || test_bit(CC33XX_FLAG_TX_PENDING, &cc->flags)))
> + ieee80211_queue_work(cc->hw, &cc->tx_work);
[Severity: Low]
Should this loop break when cc33xx_tx_complete_packet() returns an error?
If an earlier ring entry has an illegal descriptor ID and queues recovery,
continuing the loop processes the rest of the corrupted ring and can
overwrite ret with 0, causing cc->tx_work to be scheduled despite recovery
having been requested.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=11
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.h
[not found] ` <20261203070906.1294171-17-r-ramalingam@ti.com>
@ 2026-12-03 7:48 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:48 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 14 potential
issues to consider:
- [High] wifi: cc33xx: OOB write by nab_header size in
__cc33xx_cmd_send()
- [High] wifi: cc33xx: broken PLT state transitions in
cc33xx_plt_start()/stop()
- [Medium] wifi: cc33xx: NLA_U32 IE ID read with nla_get_u8() in
testmode
- [Medium] wifi: cc33xx: missing data length and alignment checks in
testmode
- [Medium] wifi: cc33xx: in-place mutation of netlink SKB payload in
testmode
- [Medium] wifi: cc33xx: missing state check and recovery sync in
testmode
- [Medium] wifi: cc33xx: transceiver role leak on error in
cc33xx_plt_init()
- [Medium] wifi: cc33xx: unsafe init_completion() re-init in
__cc33xx_cmd_send()
- [Medium] wifi: cc33xx: cc33xx_tm_detect_fem() returns unpopulated
cc->fem_manuf
- [Medium] wifi: cc33xx: PLT_FEM_DETECT re-entry leaks role and stops
active PLT
- [Medium] wifi: cc33xx: PLT state race between cc33xx_tm_cmd() and
cc33xx_unregister_hw()
- [Low] wifi: cc33xx: nla_parse_deprecated() and non-const policy in
testmode.c
- [Low] wifi: cc33xx: testmode.h missing mac80211.h include or struct
declarations
- [Low] wifi: cc33xx: split __free(kfree) declaration in
cc33xx_tm_cmd_interrogate()
--
commit e8cb943041cb92e4309b9948db961256bccd677e
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add testmode.c, testmode.h
This commit adds cfg80211 testmode support to the cc33xx driver, allowing
userspace tools to send firmware test and debug commands, control PLT mode,
and query the efuse MAC address.
> diff --git a/drivers/net/wireless/ti/cc33xx/testmode.c b/drivers/net/wireless/ti/cc33xx/testmode.c
> new file mode 100644
> index 0000000000000..5d149f958b69d
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/testmode.c
[ ... ]
> +static int cc33xx_tm_cmd_test(struct cc33xx *cc, struct nlattr *tb[])
> +{
> + int ret, len;
> + u16 buf_len;
> + struct sk_buff *skb;
> + void *buf;
> + u8 answer = 0;
> +
> + if (!tb[CC33XX_TM_ATTR_DATA])
> + return -EINVAL;
> +
> + buf = nla_data(tb[CC33XX_TM_ATTR_DATA]);
> + buf_len = nla_len(tb[CC33XX_TM_ATTR_DATA]);
[Severity: Medium]
Can passing buf directly into cc33xx_cmd_test() mutate a shared netlink
sk_buff?
netlink_unicast_kernel() clones incoming skbs for netlink taps via
skb_clone() before invoking nl80211_testmode_do(). Both cc33xx_cmd_test()
and cc33xx_cmd_debug() (called the same way from cc33xx_tm_cmd_configure())
overwrite headers and response data in place inside buf, which races with
and corrupts packets observed by nlmon. Copying CC33XX_TM_ATTR_DATA into a
driver-owned buffer before calling the command helpers would avoid this.
> + if (tb[CC33XX_TM_ATTR_ANSWER])
> + answer = nla_get_u8(tb[CC33XX_TM_ATTR_ANSWER]);
> +
> + if (buf_len > sizeof(struct cc33xx_command))
> + return -EMSGSIZE;
[Severity: Medium]
Should this also reject undersized or unaligned buf_len values?
If userspace sends a payload shorter than sizeof(struct cc33xx_cmd_header)
or not 4-byte aligned, __cc33xx_cmd_send() hits WARN_ON() and returns -EIO,
which makes cc33xx_cmd_send_failsafe() queue recovery work and reset the
chip instead of returning -EINVAL. cc33xx_tm_cmd_configure() has the same
missing minimum-length (sizeof(struct debug_header)) and 4-byte alignment
checks.
> + if (unlikely(cc->state != CC33XX_STATE_ON))
> + return -EINVAL;
> +
> + ret = cc33xx_cmd_test(cc, buf, buf_len, answer);
[Severity: High]
Can __cc33xx_cmd_send() write up to 8 bytes past the end of buf here?
__cc33xx_cmd_send() checks cc->result_length against res_len, then copies
at offset sizeof(struct nab_header):
drivers/net/wireless/ti/cc33xx/cmd.c:__cc33xx_cmd_send() {
...
if (WARN_ON(cc->result_length > res_len)) {
dev_err(cc->dev, "Error, insufficient response buffer\n");
return -EINVAL;
}
switch (id) {
case CMD_INTERROGATE:
case CMD_DEBUG_READ:
case CMD_TEST_MODE:
case CMD_BM_READ_DEVICE_INFO:
memcpy(buf + sizeof(struct nab_header), cc->command_result,
cc->result_length);
break;
...
}
When answer is non-zero, cc33xx_tm_cmd_test() passes res_len = buf_len for
the netlink attribute buffer, and cc33xx_tm_cmd_interrogate() similarly
passes res_len = sizeof(*cmd) for its kmalloc buffer. If cc->result_length
is within 7 bytes of res_len (or res_len is smaller than
sizeof(struct nab_header)), the memcpy() overruns buf by up to 8 bytes.
[Severity: Medium]
Does calling init_completion(&cc->command_complete) inside
__cc33xx_cmd_send() race with late command completion interrupts?
cc->command_complete is never initialized once at allocation time and is
instead re-initialized on every command send under cc->cmd_lock, while
parse_control_message() calls complete(&cc->command_complete) without
holding cc->cmd_lock:
CPU0 IRQ / kworker
__cc33xx_cmd_send()
wait_for_completion_timeout()
/* times out, returns -EIO */
__cc33xx_cmd_send() /* next cmd */
guard(mutex)(&cc->cmd_lock)
init_completion(&cc->command_complete)
parse_control_message()
complete(&cc->command_complete)
<-- races on waitqueue spinlock
Re-initializing the waitqueue spinlock while a late IRQ completion uses it
can corrupt the completion state. Initializing cc->command_complete once in
cc33xx_alloc_hw() and using reinit_completion() in __cc33xx_cmd_send()
would prevent this.
[ ... ]
> +static int cc33xx_tm_cmd_interrogate(struct cc33xx *cc, struct nlattr *tb[])
> +{
> + int ret;
> + struct cc33xx_command *cmd __free(kfree) = NULL;
[Severity: Low]
This isn't a bug, but per Cleanup API conventions, cmd can be defined and
initialized directly at the kzalloc_obj(*cmd) call instead of being
declared as NULL at the top of the function.
> + struct sk_buff *skb;
> + u8 ie_id;
> +
> + if (!tb[CC33XX_TM_ATTR_IE_ID])
> + return -EINVAL;
> +
> + ie_id = nla_get_u8(tb[CC33XX_TM_ATTR_IE_ID]);
[Severity: Medium]
Should CC33XX_TM_ATTR_IE_ID be read with nla_get_u32() instead of
nla_get_u8()?
cc33xx_tm_policy declares CC33XX_TM_ATTR_IE_ID as NLA_U32, so nla_get_u8()
reads the most-significant byte on big-endian hosts (dispatching ID 0 for
all valid debug commands) and silently truncates 16-bit IDs above 255 even
though cc33xx_cmd_debug_inter() takes a u16. cc33xx_tm_cmd_configure() has
the same issue.
[ ... ]
> +static int cc33xx_tm_cmd_configure(struct cc33xx *cc, struct nlattr *tb[])
> +{
[ ... ]
> + ret = cc33xx_cmd_debug(cc, ie_id, buf, buf_len);
[Severity: Medium]
Can cc33xx_tm_cmd_configure() and cc33xx_tm_cmd_set_plt_mode() issue
firmware commands while the chip is powered off or mid-recovery?
Unlike cc33xx_tm_cmd_test() and cc33xx_tm_cmd_interrogate(), neither
cc33xx_tm_cmd_configure() nor cc33xx_plt_start() checks cc->state ==
CC33XX_STATE_ON. In addition, cc33xx_tm_cmd() runs under wiphy_lock only
without cc->mutex or a CC33XX_FLAG_RECOVERY_IN_PROGRESS check, while
cc33xx_recovery_work() drops wiphy_lock before power-off and firmware boot:
CPU0 CPU1
cc33xx_recovery_work()
wiphy_unlock(cc->hw->wiphy)
cc33xx_turn_off(cc)
cc33xx_tm_cmd() /* holds wiphy_lock */
cc33xx_tm_cmd_configure()
cc33xx_cmd_debug() <-- I/O while OFF
msleep(500)
cc33xx_init_fw(cc)
cc->state = CC33XX_STATE_ON
This can attempt SDIO command I/O against a powered-off or booting chip
(stalling wiphy_lock until timeout and re-triggering recovery) and races on
cc->state, cc->roles_map, and firmware download state.
[ ... ]
> +static int cc33xx_tm_detect_fem(struct cc33xx *cc)
> +{
> + /* return FEM type */
> + int ret, len;
> + struct sk_buff *skb;
> +
> + ret = cc33xx_plt_start(cc, PLT_FEM_DETECT);
[Severity: Medium]
What happens if PLT_FEM_DETECT is requested while PLT mode is already
active?
cc33xx_plt_start() only rejects re-entry when both the requested and
current modes are PLT_ON. Calling PLT_FEM_DETECT while already in PLT_ON
runs cc33xx_plt_init() a second time, overwriting cc->plt_role_id and
leaking the first firmware transceiver role and its cc->roles_map bit, and
then out_stop unconditionally calls cc33xx_plt_stop() and tears down the
active PLT session.
> + if (ret < 0)
> + return ret;
> +
> + len = nla_total_size(sizeof(cc->fem_manuf));
> + skb = cfg80211_testmode_alloc_reply_skb(cc->hw->wiphy, len);
> + if (!skb) {
> + ret = -ENOMEM;
> + goto out_stop;
> + }
> +
> + if (nla_put(skb, CC33XX_TM_ATTR_DATA, sizeof(cc->fem_manuf),
> + &cc->fem_manuf)) {
[Severity: Medium]
Is cc->fem_manuf ever populated anywhere in the driver?
Nothing in drivers/net/wireless/ti/cc33xx/ assigns cc->fem_manuf, so
PLT_FEM_DETECT always returns 0 to userspace instead of an actual FEM
manufacturer ID or -EOPNOTSUPP.
[ ... ]
> +static int cc33xx_tm_cmd_set_plt_mode(struct cc33xx *cc, struct nlattr *tb[])
> +{
> + u32 val;
> + int ret;
> +
> + if (!tb[CC33XX_TM_ATTR_PLT_MODE])
> + return -EINVAL;
> +
> + val = nla_get_u32(tb[CC33XX_TM_ATTR_PLT_MODE]);
> +
> + switch (val) {
> + case PLT_OFF:
> + ret = cc33xx_plt_stop(cc);
> + break;
> + case PLT_ON:
> + case PLT_CHIP_AWAKE:
> + ret = cc33xx_plt_start(cc, val);
> + break;
> + case PLT_FEM_DETECT:
> + ret = cc33xx_tm_detect_fem(cc);
> + break;
[Severity: High]
Can switching to PLT_CHIP_AWAKE and then PLT_OFF disable an active role or
permanently wedge the driver in PLT_CHIP_AWAKE?
cc33xx_plt_start() skips cc33xx_plt_init() for PLT_CHIP_AWAKE, so no
transceiver role is allocated, yet cc33xx_plt_stop() unconditionally calls
cc33xx_cmd_role_stop_transceiver() and cc33xx_cmd_role_disable() before
clearing cc->plt and cc->plt_mode. Because cc->plt_role_id starts at 0,
exiting PLT_CHIP_AWAKE either disables role 0 (which may belong to an
active interface) or, after a prior PLT session leaves it at
CC33XX_INVALID_ROLE_ID, hits WARN_ON() in cc33xx_cmd_role_disable() and
returns early with cc->plt_mode permanently stuck at PLT_CHIP_AWAKE.
cc33xx_plt_start() also never checks list_empty(&cc->wlvif_list), allowing
PLT mode to start while normal interfaces are active.
[Severity: Medium]
Does cc33xx_plt_init() leak the transceiver role if cc33xx_cmd_plt_enable()
fails?
If cc33xx_cmd_plt_enable() returns an error, cc33xx_plt_init() returns
without stopping or disabling cc->plt_role_id, and cc33xx_plt_start()
leaves cc->plt false so cc33xx_plt_stop() never cleans it up.
[Severity: Medium]
Can cc33xx_tm_cmd_set_plt_mode() race with cc33xx_unregister_hw() on PLT
state and corrupt struct cc33xx?
cc33xx_unregister_hw() checks cc->plt and calls cc33xx_plt_stop() before
ieee80211_unregister_hw() without holding wiphy_lock or cc->mutex, while
cc33xx_tm_cmd() holds only wiphy_lock:
CPU0 CPU1
cc33xx_unregister_hw()
if (cc->plt) /* unlocked */
cc33xx_plt_stop()
cc33xx_cmd_role_disable()
/* checks *role_id valid */
cc33xx_tm_cmd_set_plt_mode(PLT_OFF)
cc33xx_plt_stop()
cc33xx_cmd_role_disable()
__clear_bit(*role_id, ...)
*role_id = CC33XX_INVALID_ROLE_ID
__clear_bit(*role_id, ...)
<-- clears bit 255 past cc->roles_map
Because CC33XX_INVALID_ROLE_ID is 0xff while cc->roles_map only holds 4
bits, a racing double stop can clear bit 255 past cc->roles_map. A
concurrent PLT_ON can also start PLT during teardown, and cc33xx_plt_stop()
resets cc->rx_counter without cc->mutex, racing with
cc33xx_rx_handle_packet().
[ ... ]
> +int cc33xx_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> + void *data, int len)
> +{
> + struct cc33xx *cc = hw->priv;
> + struct nlattr *tb[TM_ATTR_MAX + 1];
> + u32 nla_cmd;
> + int err;
> +
> + err = nla_parse_deprecated(tb, TM_ATTR_MAX, data, len,
> + cc33xx_tm_policy, NULL);
[Severity: Low]
Should this new netlink parser use strict nla_parse() instead of
nla_parse_deprecated(), and can cc33xx_tm_policy be declared static const?
> diff --git a/drivers/net/wireless/ti/cc33xx/testmode.h b/drivers/net/wireless/ti/cc33xx/testmode.h
> new file mode 100644
> index 0000000000000..adb98c117b608
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/testmode.h
> @@ -0,0 +1,12 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
> + */
> +
> +#ifndef __TESTMODE_H__
> +#define __TESTMODE_H__
> +
> +int cc33xx_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> + void *data, int len);
[Severity: Low]
Should testmode.h include net/mac80211.h or forward-declare struct
ieee80211_hw and struct ieee80211_vif so the header is self-contained?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=16
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 14/17] wifi: cc33xx: Add conf.h
[not found] ` <20261203070906.1294171-15-r-ramalingam@ti.com>
@ 2026-12-03 7:50 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:50 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] wifi: cc33xx: slab out-of-bounds read past cc->cmd_buf in
send_buffer()
- [Medium] wifi: cc33xx: host-endian payload fields in little-endian
cc33xx_conf_file
- [Medium] wifi: cc33xx: unrolled scalar fields in conf.h cause OOB
pointer arithmetic
- [Medium] wifi: cc33xx: out-of-bounds read in cc33xx_acx_get_tx_rate()
when tx_rate is 0
- [Medium] wifi: cc33xx: cc33xx_init_ieee80211() unconditionally
overwrites he_enable
- [Medium] wifi: cc33xx: cc33xx_ini_bin_init() leaves all-zero conf on
fallback
- [Low] wifi: cc33xx: conflicting CONF_PS_SCHEME and PS_SCHEME enum
values
- [Low] wifi: cc33xx: unused CC33XX_CONF_VERSION check and dead defs in
conf.h
--
commit 660c730a527a7e9f1d8ab53bd35ec0f25cac9f39
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add conf.h
This commit adds conf.h defining the binary configuration file layout,
hardware rate definitions, and firmware/driver control structures for the
TI CC33xx wireless driver.
> diff --git a/drivers/net/wireless/ti/cc33xx/conf.h b/drivers/net/wireless/ti/cc33xx/conf.h
> new file mode 100644
> index 0000000000000..a6aa2c0dc9630
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/conf.h
> @@ -0,0 +1,1241 @@
[ ... ]
> +struct cc33xx_conf_header {
> + __le32 magic;
> + __le32 version;
> + __le32 checksum;
> +} __packed;
> +
> +#define CC33XX_CONF_MAGIC 0x10e100ca
> +#define CC33XX_CONF_VERSION 0x01070070
> +#define CC33XX_CONF_MASK 0x0000ffff
[Severity: Medium]
What populates cc->conf when loading the configuration binary fails?
In drivers/net/wireless/ti/cc33xx/main.c, cc33xx_ini_bin_init() logs
"falling back to default config" and returns 0 when
cc33xx_load_ini_bin_file() fails, leaving cc->conf all-zero. Probe then
downloads an all-zero struct cc33xx_conf_file to the firmware, and bringing
up any VIF hits WARN_ON(tx_settings->ac_conf_count != CONF_TX_MAX_AC_COUNT)
in cc33xx_init_vif_specific() and fails with -EINVAL.
In addition, cc33xx_load_ini_bin_file() never checks header.version against
CC33XX_CONF_VERSION or validates header.checksum, so a mismatched or
corrupted binary of the same size is silently accepted.
> +#define CC33X_CONF_SIZE (sizeof(struct cc33xx_conf_file))
[Severity: High]
Can send_buffer() read past the end of cc->cmd_buf during INI download?
CC33X_CONF_SIZE is 1353 bytes, which sizes cc->cmd_buf to
CC33XX_INI_CMD_MAX_SIZE (1373 bytes) in
drivers/net/wireless/ti/cc33xx/cc33xx.h. During firmware init,
cc33xx_download_ini_params_and_wait() calls
cc33xx_set_max_buffer_size(cc, INI_MAX_BUFFER_SIZE), which adds the command
header and u32 size a second time (1393 bytes), and send_buffer() then
aligns the transfer length up to 256 bytes (1536 bytes):
drivers/net/wireless/ti/cc33xx/cmd.c:cc33xx_set_max_buffer_size() {
case INI_MAX_BUFFER_SIZE:
cc->max_cmd_size = CC33XX_INI_CMD_MAX_SIZE;
cc->max_cmd_size += sizeof(struct cc33xx_cmd_ini_params_download);
cc->max_cmd_size += sizeof(u32);
break;
}
drivers/net/wireless/ti/cc33xx/cmd.c:send_buffer() {
max_cmd_size_align = __ALIGN_MASK(cc->max_cmd_size,
CC33XX_BUS_BLOCK_SIZE * 2 - 1);
return cc33xx_raw_write(cc, cmd_box_addr, cc->cmd_buf,
max_cmd_size_align, true);
}
Passing 1536 bytes to sdio_writesb() reads 163 bytes past cc->cmd_buf and
roughly 114 bytes past the end of struct cc33xx on every boot, triggering
KASAN slab-out-of-bounds reports and transmitting adjacent heap memory over
SDIO. Even without the double header addition, aligning 1373 up to 256
bytes still requires 1536 bytes, so CC33XX_CMD_BUFFER_SIZE should be
aligned to CC33XX_BUS_BLOCK_SIZE * 2 as well.
[ ... ]
> +enum {
> + CONF_HW_RATE_INDEX_1MBPS = 1,
> + CONF_HW_RATE_INDEX_2MBPS = 2,
> + CONF_HW_RATE_INDEX_5_5MBPS = 3,
> + CONF_HW_RATE_INDEX_11MBPS = 4,
> + CONF_HW_RATE_INDEX_6MBPS = 5,
> + CONF_HW_RATE_INDEX_9MBPS = 6,
> + CONF_HW_RATE_INDEX_12MBPS = 7,
> + CONF_HW_RATE_INDEX_18MBPS = 8,
> + CONF_HW_RATE_INDEX_24MBPS = 9,
> + CONF_HW_RATE_INDEX_36MBPS = 10,
> + CONF_HW_RATE_INDEX_48MBPS = 11,
> + CONF_HW_RATE_INDEX_54MBPS = 12,
> + CONF_HW_RATE_INDEX_MCS0 = 13,
> + CONF_HW_RATE_INDEX_MCS1 = 14,
> + CONF_HW_RATE_INDEX_MCS2 = 15,
> + CONF_HW_RATE_INDEX_MCS3 = 16,
> + CONF_HW_RATE_INDEX_MCS4 = 17,
> + CONF_HW_RATE_INDEX_MCS5 = 18,
> + CONF_HW_RATE_INDEX_MCS6 = 19,
> + CONF_HW_RATE_INDEX_MCS7 = 20,
> +
> + CONF_HW_RATE_INDEX_MAX = CONF_HW_RATE_INDEX_MCS7,
> +};
[Severity: Medium]
Can cc33xx_acx_get_tx_rate() read out of bounds when firmware reports
tx_rate 0?
Because the hardware rate indices start at 1, a zero tx_rate from firmware
falls into the else branch in drivers/net/wireless/ti/cc33xx/acx.c:
drivers/net/wireless/ti/cc33xx/acx.c:cc33xx_acx_get_tx_rate() {
if (acx->tx_rate >= CONF_HW_RATE_INDEX_MCS0)
sinfo->txrate.mcs = acx->tx_rate - CONF_HW_RATE_INDEX_MCS0;
else
sinfo->txrate.legacy = cc33xx_idx_to_rate_100kbps[acx->tx_rate - 1];
}
With u16 acx->tx_rate == 0, acx->tx_rate - 1 promotes to -1 and reads 2
bytes before cc33xx_idx_to_rate_100kbps[] in .rodata, triggering KASAN or
UBSAN global-out-of-bounds reports when NL80211_CMD_GET_STATION runs.
Values above CONF_HW_RATE_INDEX_MAX (such as CONF_HW_RXTX_RATE_UNSUPPORTED)
also pass the >= CONF_HW_RATE_INDEX_MCS0 check and report an invalid MCS.
Validating that tx_rate is within [CONF_HW_RATE_INDEX_1MBPS,
CONF_HW_RATE_INDEX_MAX] would prevent both.
[ ... ]
> +struct cc33xx_clk_cfg {
> + u32 n;
> + u32 m;
> + u32 p;
> + u32 q;
> + u8 swallow;
> +};
[Severity: Low]
Are struct cc33xx_clk_cfg, the CLOCK_CONFIG_* enum, and struct
conf_channel_power_limit used anywhere in cc33xx?
None of these definitions are referenced in the driver or embedded in
struct cc33xx_conf_file. CC33XX_CONF_VERSION and CC33XX_CONF_MASK are also
unused because cc33xx_load_ini_bin_file() skips version checking (and logs
__le32 header.magic without le32_to_cpu()). Finally, CC33X_CONF_SIZE is
missing an X compared to the other CC33XX_CONF_* macros, and several array
sizes (507, 13, 3, 2) duplicate the adjacent REG_RULES_COUNT,
ACX_RATE_MGMT_NUM_OF_RATES, CONF_BCN_IE_OUI_LEN, and CONF_BCN_IE_VER_LEN
macros.
[ ... ]
> +enum {
> + CONF_PS_SCHEME_LEGACY = 0,
> + CONF_PS_SCHEME_UPSD_TRIGGER = 1,
> + CONF_PS_SCHEME_LEGACY_PSPOLL = 2,
> + CONF_PS_SCHEME_SAPSD = 3,
> +};
[Severity: Low]
Do these CONF_PS_SCHEME_* values conflict with the PS_SCHEME_* enum in
drivers/net/wireless/ti/cc33xx/acx.h?
acx.h defines PS_SCHEME_MIXED_MODE = 2, PS_SCHEME_LEGACY_PSPOLL = 3, and
PS_SCHEME_SAPSD = 4, whereas here 2 is LEGACY_PSPOLL and 3 is SAPSD. Both
enums are passed into cc33xx_tx_param_cfg() for the same firmware ps_scheme
field; today cc33xx_op_conf_tx() only passes 0 and 1, which match, but
using any higher value would silently misconfigure the firmware. Removing
the duplicate enum and using PS_SCHEME_* consistently would avoid that.
[ ... ]
> + /*struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT];*/
> + struct conf_tx_ac_category ac_conf0;
> + struct conf_tx_ac_category ac_conf1;
> + struct conf_tx_ac_category ac_conf2;
> + struct conf_tx_ac_category ac_conf3;
[Severity: Medium]
Can stepping pointers across unrolled scalar fields like ac_conf0..ac_conf3
trigger undefined behavior and bounds-check failures?
cc33xx_init_vif_specific() in drivers/net/wireless/ti/cc33xx/init.c starts
at &tx_settings->ac_conf0 and increments conf_ac++ across
ac_conf1..ac_conf3. Similarly, struct conf_conn_settings unrolls
bcn_filt_ie0..bcn_filt_ie31 (and struct conf_tx_settings unrolls
tid_conf0..tid_conf7), and cc33xx_acx_beacon_filter_table() in acx.c walks
r++ from &bcn_filt_ie0 up to r + bcn_filt_ie_count and passes r->oui and
r->version to memcpy().
Advancing a pointer past a single non-array member into neighboring fields
is C undefined behavior and can trip UBSAN, FORTIFY_SOURCE subobject bounds
checks, or -Warray-bounds. Since all of these structs are __packed,
declaring fixed-size arrays (ac_conf[CONF_TX_MAX_AC_COUNT],
tid_conf[CONF_TX_MAX_TID_COUNT], and
bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT]) keeps the identical wire layout.
[ ... ]
> +struct cc33xx_mac_conf {
> + u8 ps_scheme;
> + u8 he_enable;
> + u8 ap_max_num_stations;
> +} __packed;
[Severity: Medium]
Does cc33xx_init_ieee80211() unconditionally undo clearing HE capabilities
when he_enable is 0?
In drivers/net/wireless/ti/cc33xx/main.c:
drivers/net/wireless/ti/cc33xx/main.c:cc33xx_init_ieee80211() {
if (!cc->conf.mac.he_enable) {
cc->bands[NL80211_BAND_2GHZ].iftype_data = NULL;
cc->bands[NL80211_BAND_2GHZ].n_iftype_data = 0;
cc->bands[NL80211_BAND_5GHZ].iftype_data = NULL;
cc->bands[NL80211_BAND_5GHZ].n_iftype_data = 0;
}
ieee80211_set_sband_iftype_data(&cc->bands[NL80211_BAND_2GHZ], iftype_data_2ghz);
ieee80211_set_sband_iftype_data(&cc->bands[NL80211_BAND_5GHZ], iftype_data_5ghz);
}
The trailing ieee80211_set_sband_iftype_data() calls immediately overwrite
iftype_data and n_iftype_data on both bands, so mac80211 still advertises
HE support even when the OEM configuration disables it in firmware.
Moving those calls into an else branch would fix this.
[ ... ]
> +struct cc33xx_conf_file {
> + struct cc33xx_conf_header header;
> + struct cc33xx_phy_conf phy;
> + struct cc33xx_mac_conf mac;
> + struct cc33xx_core_conf core;
> + struct cc33xx_host_conf host_conf;
> +} __packed;
[Severity: Medium]
Should the multi-byte fields inside struct cc33xx_conf_file use __le16 and
__le32 instead of host-endian u16 and u32?
struct cc33xx_conf_header uses __le32, cc33xx_load_ini_bin_file() copies
the little-endian binary directly into cc->conf via memcpy(), and
cc33xx_download_ini_params_and_wait() sends cc->conf verbatim to firmware.
Because Kconfig does not restrict CC33XX to little-endian systems, reading
u16 and u32 fields directly on big-endian hosts produces byte-swapped
values in callers such as cc33xx_scan_get_channels(),
cc33xx_tx_param_cfg(), cc33xx_event_beacon_loss(), and
cc33xx_init_vif_data(), and prevents sparse from flagging the missing
le16_to_cpu() and le32_to_cpu() conversions.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=14
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h
2026-12-03 7:09 ` [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h Ramesh Ramalingam
@ 2026-12-03 7:52 ` sashiko-bot
0 siblings, 0 replies; 30+ messages in thread
From: sashiko-bot @ 2026-12-03 7:52 UTC (permalink / raw)
To: Ramesh Ramalingam; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] wifi: cc33xx: heap buffer overflow in
cc33xx_cmd_build_probe_req()
- [High] wifi: cc33xx: AB-BA deadlock in cc33xx_scan_completed() via
wiphy_lock()
- [Medium] wifi: cc33xx: host-endian fields in scheduled scan plan
commands
- [Medium] wifi: cc33xx: info.aborted left false on timeout in
cc33xx_scan_complete_work()
- [Medium] wifi: cc33xx: __cc33xx_op_remove_interface() omits
scan_complete_work cancel
- [Medium] wifi: cc33xx: CC33XX_SCAN_STATE_DONE never set in
cc33xx_scan_completed()
- [Medium] wifi: cc33xx: unconditional 10 ms sleep under wiphy_lock on
every scan
- [Medium] wifi: cc33xx: unconditional SSID filtering in
cc33xx_sched_scan_start()
- [Medium] wifi: cc33xx: ignore return value of
cc33xx_set_scan_chan_params()
- [Medium] wifi: cc33xx: race between scan timeout timer and
cc33xx_scan_completed()
- [Low] wifi: cc33xx: __free(kfree) pointers split from allocation in
scan.c
- [Low] wifi: cc33xx: DFS dwell time discarded in
cc33xx_adjust_channels()
- [Low] wifi: cc33xx: cc33xx_sched_scan_start() checks role_id after
sending FW cmd
--
commit 0ac5043da0c566dad2178179ebf5d815a65e98df
Author: Michael Nemanov <michael.nemanov@ti.com>
wifi: cc33xx: Add scan.c, scan.h
This commit adds one-shot and scheduled hardware scan support for the
cc33xx wireless driver, including channel packing, probe request IE
configuration, scan start/stop commands, and completion handling.
> diff --git a/drivers/net/wireless/ti/cc33xx/scan.c b/drivers/net/wireless/ti/cc33xx/scan.c
> new file mode 100644
> index 0000000000000..a109ea034396c
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/scan.c
[ ... ]
> +struct scan_one_shot_info {
> + u8 passive[CONN_SCAN_MAX_BAND];
> + u8 active[CONN_SCAN_MAX_BAND];
> + u8 dfs;
> +
> + struct conn_scan_ch_info channel_list[CONN_SCAN_MAX_CHANNELS_ALL_BANDS];
> + struct conn_scan_dwell_info dwell_info[CONN_SCAN_MAX_BAND];
> + u8 reserved;
> +};
> +
> +struct sched_scan_plan_cmd {
> + u32 interval;
> + u32 iterations;
> +};
> +
> +struct scan_periodic_info {
> + struct sched_scan_plan_cmd sched_scan_plans[SCAN_MAX_SCHED_SCAN_PLANS];
> + u16 sched_scan_plans_num;
[Severity: Medium]
Should sched_scan_plan_cmd and scan_periodic_info use __le32 and __le16
instead of host-endian u32 and u16?
Other firmware command structures in this driver are little-endian and
packed, but cc33xx_sched_scan_start() copies req->scan_plans with a raw
memcpy() and assigns req->n_scan_plans directly without byte swapping,
sending byte-swapped scheduled scan parameters on big-endian hosts.
Both struct sched_scan_plan_cmd and struct scan_one_shot_info also omit
__packed even though they are embedded inside packed
cc33xx_cmd_scan_params at a 2-byte aligned offset. Converting each plan
element with cpu_to_le32() and the count with cpu_to_le16() would also
decouple the firmware ABI from struct cfg80211_sched_scan_plan.
[ ... ]
> + ch_params_list = cmd_channels->channels_5;
> + for (j = 0; j < MAX_CHANNELS_5GHZ; ++i, ++j) {
> + ch_info_list[i].channel = ch_params_list[j].channel;
> + ch_info_list[i].flags = ch_params_list[j].flags;
> + ch_info_list[i].tx_power_att = ch_params_list[j].tx_power_att;
> + }
> +
> + channel = &ch_params_list[0];
> + band = NL80211_BAND_5GHZ;
> + dwell_info[band].min_duration = channel->min_duration;
> + dwell_info[band].max_duration = channel->max_duration;
> + dwell_info[band].passive_duration = channel->passive_duration;
> +}
[Severity: Low]
Does taking passive_duration from channels_5[0] silently discard
dwell_time_dfs?
cc33xx_set_scan_chan_params() places non-DFS passive 5 GHz channels at
the start of channels_5[] before DFS channels. When a 5 GHz passive scan
includes both non-DFS and DFS channels, channels_5[0] is a non-DFS entry,
so dwell_info[NL80211_BAND_5GHZ].passive_duration gets dwell_time_passive
instead of the longer dwell_time_dfs configured in
cc33xx_scan_get_channels().
> +
> +static int cc33xx_cmd_build_probe_req(struct cc33xx *cc,
> + struct cc33xx_vif *wlvif, u8 role_id,
> + u8 scan_type, const u8 *ssid,
> + size_t ssid_len, const u8 *ie0,
> + size_t ie0_len, const u8 *ie1,
> + size_t ie1_len)
> +{
> + struct ieee80211_vif *vif = cc33xx_wlvif_to_vif(wlvif);
> + struct sk_buff *skb = NULL;
> + struct cc33xx_cmd_set_ies *cmd __free(kfree) = NULL;
> + int ret;
> +
> + cmd = kzalloc_obj(*cmd);
[Severity: Low]
This isn't a bug, but per cleanup.h conventions __free(kfree) pointers
should be declared and initialized at their allocation site rather than
initialized to NULL at the top of the function. The same pattern appears
in cc33xx_scan_send(), cc33xx_sched_scan_start(), and
__cc33xx_scan_stop().
[ ... ]
> + cmd->len = cpu_to_le16(skb->len - sizeof(struct ieee80211_hdr_3addr));
> +
> + if (skb->data) {
> + memcpy(cmd->data,
> + skb->data + sizeof(struct ieee80211_hdr_3addr), le16_to_cpu(cmd->len));
> + }
[Severity: High]
Can this memcpy() overflow cmd->data?
cmd->data is MAX_EXTRA_IES_LEN (512) bytes, while cc33xx_init_ieee80211()
in drivers/net/wireless/ti/cc33xx/main.c sets wiphy->max_sched_scan_ie_len
to 488 bytes (512 - 24). For scheduled scans, ieee80211_register_hw()
does not subtract mac80211's own band IEs from max_sched_scan_ie_len, so
cc33xx_sched_scan_start() passes up to 488 bytes of userspace common_ies
plus the 2.4 GHz band IEs and the SSID IE (2 + ssid_len bytes) into
cc33xx_cmd_build_probe_req(), overflowing the heap-allocated
cc33xx_cmd_set_ies (or panicking under CONFIG_FORTIFY_SOURCE). One-shot
scans can also exceed 512 bytes by the up to 34-byte SSID IE.
Validating the IE length against sizeof(cmd->data) before copying (and
freeing skb on error) and reserving SSID and band IE headroom in
max_scan_ie_len and max_sched_scan_ie_len would prevent the overflow.
> +
> + usleep_range(10000, 11000);
> + ret = cc33xx_cmd_send(cc, CMD_SET_PROBE_IE, cmd, sizeof(*cmd), 0);
[Severity: Medium]
Why is this unconditional 10-11 ms sleep needed before the synchronous
CMD_SET_PROBE_IE command?
cc33xx_cmd_build_probe_req() runs under wiphy_lock (twice per dual-band
scan because SINGLE_SCAN_ON_ALL_BANDS is not set), so this stalls
cfg80211/mac80211 control paths on every scan. If a firmware event that
takes wiphy_lock arrives during the sleep, it also blocks
irq_deferred_work and netstack_work on the single-threaded
cc->freezable_wq, stalling RX and TX processing for 10-11 ms. If this
delay is required by a firmware timing constraint, it should be
documented; otherwise it can be removed.
[ ... ]
> + cc33xx_set_scan_chan_params(cc, cmd_channels, req->channels,
> + req->n_channels, req->n_ssids,
> + SCAN_TYPE_SEARCH);
> +
> + cc33xx_adjust_channels(&cmd->params, cmd_channels, cmd->scan_type);
[Severity: Medium]
Should cc33xx_scan_send() check the boolean return value of
cc33xx_set_scan_chan_params() and return -EINVAL when it is false?
If a regulatory update disables all channels in a pending or multi-band
scan request before mac80211 invokes drv_hw_scan(),
cc33xx_scan_get_channels() skips every channel and
cc33xx_set_scan_chan_params() returns false, yet the driver still sends
CMD_SCAN with zero channels and zero dwell times, risking a 30-second
scan timeout and hardware recovery.
cc33xx_sched_scan_start() similarly ignores the return value, which
prevents ieee80211_reconfig() from stopping a restarted scheduled scan
whose channels were disabled by a regulatory update.
[ ... ]
> + if (n_ssids <= 5) {
> + alloc_size += (n_ssids * sizeof(struct cc33xx_ssid));
> + } else { /* n_ssids > 5 */
> + ssid_list->scan_type = SCAN_REQUEST_CONNECT_PERIODIC_SCAN;
> + ret = cc33xx_cmd_send(cc, CMD_CONNECTION_SCAN_SSID_CFG,
> + ssid_list, sizeof(*ssid_list), 0);
> + if (ret < 0) {
> + dev_err(cc->dev, "cmd sched scan ssid list failed\n");
> + return ret;
> + }
> + }
> +
> + cmd = kzalloc(alloc_size, GFP_KERNEL);
> + if (!cmd)
> + return -ENOMEM;
> +
> + cmd->role_id = wlvif->role_id;
> +
> + if (WARN_ON(cmd->role_id == CC33XX_INVALID_ROLE_ID))
> + return -EINVAL;
[Severity: Low]
Can CMD_CONNECTION_SCAN_SSID_CFG be sent with CC33XX_INVALID_ROLE_ID here?
During hardware recovery, cc33xx_recovery_work() removes the interface
(setting wlvif->role_id to CC33XX_INVALID_ROLE_ID) and cc33xx_init_fw()
sets cc->state to CC33XX_STATE_ON before ieee80211_restart_hw() re-adds
interfaces. If a scheduled scan with more than 5 SSIDs arrives in that
window, cc33xx_sched_scan_start() sends CMD_CONNECTION_SCAN_SSID_CFG
with role_id 0xff before the WARN_ON() check runs, which can fail and
re-queue recovery. Moving the role_id check to the start of the function
avoids sending the invalid command.
[ ... ]
> + cmd->filter = 1;
> + cmd->num_of_ssids = n_ssids;
[Severity: Medium]
Should cmd->filter be set to 1 only when req->match_sets contains SSID
filters?
cc33xx_scan_sched_scan_ssid_list() handles unfiltered scheduled scans
(when no match_sets have SSIDs) but only returns cmd->n_ssids, so
cc33xx_sched_scan_start() unconditionally sets cmd->filter = 1. That
tells the firmware to forward only results matching the configured SSID
list, silently dropping discovered BSSes on unfiltered scheduled scans.
[ ... ]
> +void cc33xx_scan_complete_work(struct wiphy *wiphy,
> + struct wiphy_work *work)
> +
> +{
> + struct cc33xx *cc;
> + struct cfg80211_scan_info info = {
> + .aborted = false,
> + };
> +
> + cc = container_of(work, struct cc33xx, scan_complete_work.work);
> +
> + if (unlikely(cc->state != CC33XX_STATE_ON))
> + return;
> +
> + if (cc->scan.state == CC33XX_SCAN_STATE_IDLE)
> + return;
> +
> + cc->scan.state = CC33XX_SCAN_STATE_IDLE;
> + cc->scan.req = NULL;
> + cc->scan_wlvif = NULL;
> +
> + if (cc->scan.failed) {
> + dev_info(cc->dev, "Scan completed due to error.\n");
> + cc33xx_queue_recovery_work(cc);
> + }
> +
> + ieee80211_scan_completed(cc->hw, &info);
> +}
[Severity: Medium]
Should info.aborted be set to true when cc->scan.failed is true?
Leaving info.aborted false on a scan timeout tells mac80211 that the scan
succeeded. Because SINGLE_SCAN_ON_ALL_BANDS is not set,
__ieee80211_scan_completed() immediately calls drv_hw_scan() for the next
band against the wedged firmware while holding wiphy_lock, and on the
final band cfg80211 reports normal scan completion instead of an abort.
[ ... ]
> + cc->scan_wlvif = wlvif;
> + cc->scan.req = req;
> +
> + wiphy_delayed_work_queue(cc->hw->wiphy, &cc->scan_complete_work,
> + msecs_to_jiffies(CC33XX_SCAN_TIMEOUT));
[Severity: Medium]
Can a stale scan_complete_work timer from a removed interface abort a
later scan on another interface?
If cc33xx_op_cancel_hw_scan() fails during interface teardown,
__cc33xx_op_remove_interface() in drivers/net/wireless/ti/cc33xx/main.c
resets cc->scan.state and calls ieee80211_scan_completed() without
cancelling cc->scan_complete_work. When another interface stays up, the
30-second timer remains armed:
CPU0 CPU1 (<softirq>)
__cc33xx_op_remove_interface()
cc->scan.state = IDLE
(timer not cancelled)
wiphy_delayed_work_timer()
wiphy_work_queue(scan_complete_work)
cc33xx_op_hw_scan() -> cc33xx_scan()
cc->scan.state = ACTIVE
cc->scan.failed = true
wiphy_delayed_work_queue(..., 30s)
cfg80211_wiphy_work()
cc33xx_scan_complete_work() <-- completes new scan, queues recovery
Because wiphy_delayed_work_queue() with a non-zero delay only calls
mod_timer() and does not dequeue an already-queued work item, the stale
work runs immediately after cc33xx_op_hw_scan() releases wiphy_lock,
prematurely finishing the new scan and triggering hardware recovery.
Calling wiphy_delayed_work_cancel() in __cc33xx_op_remove_interface()
would close this window.
[ ... ]
> +void cc33xx_scan_completed(struct cc33xx *cc)
> +{
> + wiphy_lock(cc->hw->wiphy);
[Severity: High]
Can taking wiphy_lock() here ABBA deadlock with cc33xx_cmd_remove_peer()?
cc33xx_scan_completed() runs inside process_deferred_events() on the
single-threaded cc->freezable_wq, which is also the only context that
processes PEER_REMOVE_COMPLETE_EVENT_ID and completes
cc->peer_remove_complete. If a station disconnects from an AP interface
while a scan completes:
CPU0 CPU1
---- ----
lock(&wiphy->mtx)
process_deferred_events()
cc33xx_scan_completed()
lock(&wiphy->mtx)
wait_for_completion_timeout(
&cc->peer_remove_complete)
*** DEADLOCK ***
CPU0: drv_sta_state() -> cc33xx_op_sta_state() -> cc33xx_sta_remove()
-> cc33xx_cmd_remove_peer()
CPU1: cc33xx_irq_work() -> process_deferred_events()
-> cc33xx_scan_completed()
This stalls wiphy->mtx and cc->freezable_wq (blocking RX, TX completion,
and event handling) until the 5-second CC33XX_EVENT_TIMEOUT expires,
causing cc33xx_cmd_remove_peer() to fail with -ETIMEDOUT and trigger
hardware recovery.
> + if (cc->scan_wlvif) {
> + cc->scan.failed = false;
[Severity: Medium]
Should cc->scan.state be set to CC33XX_SCAN_STATE_DONE here?
cc33xx_op_cancel_hw_scan() in drivers/net/wireless/ti/cc33xx/main.c checks
for CC33XX_SCAN_STATE_DONE to skip sending CMD_STOP_SCAN once the
firmware has finished scanning, but CC33XX_SCAN_STATE_DONE is never
assigned anywhere in the driver. If a scan cancel arrives between
cc33xx_scan_completed() and scan_complete_work, the driver sends a
spurious CMD_STOP_SCAN for an already-completed scan, which if rejected
by firmware causes cc33xx_op_cancel_hw_scan() to return early and queue
hardware recovery.
> + wiphy_delayed_work_queue(cc->hw->wiphy, &cc->scan_complete_work,
> + msecs_to_jiffies(0));
> + }
> + wiphy_unlock(cc->hw->wiphy);
> +}
[Severity: Medium]
Can an in-flight timeout timer race with wiphy_delayed_work_queue(..., 0)
and abort the next band's scan?
On the zero-delay path, wiphy_delayed_work_queue() calls non-synchronous
timer_delete() instead of waiting for a running timer callback. Because
rdev->wiphy_work_list is processed FIFO and SINGLE_SCAN_ON_ALL_BANDS is
not set, an in-flight timer from scan 1 can queue scan_complete_work
behind local->scan_work:
CPU0 CPU1 (<softirq>)
wiphy_delayed_work_timer()
cc33xx_scan_completed()
cc->scan.failed = false
wiphy_delayed_work_queue(..., 0)
timer_delete() (no wait)
wiphy_work_queue(scan_complete)
cfg80211_wiphy_work()
cc33xx_scan_complete_work()
ieee80211_scan_completed()
queue local->scan_work
wiphy_work_queue(scan_complete)
ieee80211_scan_work()
cc33xx_scan() (next band)
cc->scan.state = ACTIVE
cc->scan.failed = true
cc33xx_scan_complete_work() <-- aborts scan 2, queues recovery
Calling wiphy_delayed_work_cancel() before queuing scan_complete_work
would synchronize with the timer callback via timer_delete_sync().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=13
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2026-12-03 7:52 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
2026-12-03 7:20 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
2026-12-03 7:31 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
2026-12-03 7:26 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
2026-12-03 7:33 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
2026-12-03 7:42 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
2026-12-03 7:32 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
2026-12-03 7:31 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
2026-12-03 7:38 ` sashiko-bot
2026-12-03 7:08 ` [PATCH v6 09/17] wifi: cc33xx: Add main.c Ramesh Ramalingam
2026-12-03 7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
2026-12-03 7:33 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
2026-12-03 7:47 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
2026-12-03 7:43 ` sashiko-bot
2026-12-03 7:09 ` [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h Ramesh Ramalingam
2026-12-03 7:52 ` sashiko-bot
[not found] ` <20261203070906.1294171-16-r-ramalingam@ti.com>
2026-12-03 7:43 ` [PATCH v6 15/17] wifi: cc33xx: Add ps.c, ps.h sashiko-bot
[not found] ` <20261203070906.1294171-18-r-ramalingam@ti.com>
2026-12-03 7:46 ` [PATCH v6 17/17] wifi: cc33xx: Add Kconfig, Makefile sashiko-bot
[not found] ` <20261203070906.1294171-17-r-ramalingam@ti.com>
2026-12-03 7:48 ` [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.h sashiko-bot
[not found] ` <20261203070906.1294171-15-r-ramalingam@ti.com>
2026-12-03 7:50 ` [PATCH v6 14/17] wifi: cc33xx: Add conf.h sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox