xref: /linux/drivers/net/wireless/silabs/wfx/wfx.h (revision 94737ef56b610d94a24fadfb8386fc17dbd79ddd)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Common private data.
4  *
5  * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
6  * Copyright (c) 2010, ST-Ericsson
7  * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
8  * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
9  */
10 #ifndef WFX_H
11 #define WFX_H
12 
13 #include <linux/completion.h>
14 #include <linux/workqueue.h>
15 #include <linux/mutex.h>
16 #include <linux/nospec.h>
17 #include <net/mac80211.h>
18 
19 #include "bh.h"
20 #include "data_tx.h"
21 #include "main.h"
22 #include "queue.h"
23 #include "hif_tx.h"
24 
25 #define USEC_PER_TXOP 32 /* see struct ieee80211_tx_queue_params */
26 #define USEC_PER_TU 1024
27 
28 struct wfx_hwbus_ops;
29 
30 struct wfx_dev {
31 	struct wfx_platform_data   pdata;
32 	struct device              *dev;
33 	struct ieee80211_hw        *hw;
34 	struct ieee80211_vif       *vif[2];
35 	struct mac_address         addresses[2];
36 	const struct wfx_hwbus_ops *hwbus_ops;
37 	void                       *hwbus_priv;
38 
39 	u8                         keyset;
40 	struct completion          firmware_ready;
41 	struct wfx_hif_ind_startup hw_caps;
42 	struct wfx_hif             hif;
43 	struct delayed_work        cooling_timeout_work;
44 	bool                       poll_irq;
45 	bool                       chip_frozen;
46 	struct mutex               conf_mutex;
47 
48 	struct wfx_hif_cmd         hif_cmd;
49 	struct sk_buff_head        tx_pending;
50 	wait_queue_head_t          tx_dequeue;
51 	atomic_t                   tx_lock;
52 
53 	atomic_t                   packet_id;
54 	u32                        key_map;
55 
56 	struct wfx_hif_rx_stats    rx_stats;
57 	struct mutex               rx_stats_lock;
58 	struct wfx_hif_tx_power_loop_info tx_power_loop_info;
59 	struct mutex               tx_power_loop_info_lock;
60 };
61 
62 struct wfx_vif {
63 	struct wfx_dev             *wdev;
64 	struct ieee80211_vif       *vif;
65 	struct ieee80211_channel   *channel;
66 	int                        id;
67 
68 	u32                        link_id_map;
69 
70 	bool                       after_dtim_tx_allowed;
71 	bool                       join_in_progress;
72 
73 	struct delayed_work        beacon_loss_work;
74 
75 	struct wfx_queue           tx_queue[4];
76 	struct wfx_tx_policy_cache tx_policy_cache;
77 	struct work_struct         tx_policy_upload_work;
78 
79 	struct work_struct         update_tim_work;
80 
81 	unsigned long              uapsd_mask;
82 
83 	/* avoid some operations in parallel with scan */
84 	struct mutex               scan_lock;
85 	struct work_struct         scan_work;
86 	struct completion          scan_complete;
87 	int                        scan_nb_chan_done;
88 	bool                       scan_abort;
89 	struct ieee80211_scan_request *scan_req;
90 
91 	struct completion          set_pm_mode_complete;
92 };
93 
94 static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id)
95 {
96 	if (vif_id >= ARRAY_SIZE(wdev->vif)) {
97 		dev_dbg(wdev->dev, "requesting non-existent vif: %d\n", vif_id);
98 		return NULL;
99 	}
100 	vif_id = array_index_nospec(vif_id, ARRAY_SIZE(wdev->vif));
101 	if (!wdev->vif[vif_id])
102 		return NULL;
103 	return (struct wfx_vif *)wdev->vif[vif_id]->drv_priv;
104 }
105 
106 static inline struct wfx_vif *wvif_iterate(struct wfx_dev *wdev, struct wfx_vif *cur)
107 {
108 	int i;
109 	int mark = 0;
110 	struct wfx_vif *tmp;
111 
112 	if (!cur)
113 		mark = 1;
114 	for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
115 		tmp = wdev_to_wvif(wdev, i);
116 		if (mark && tmp)
117 			return tmp;
118 		if (tmp == cur)
119 			mark = 1;
120 	}
121 	return NULL;
122 }
123 
124 static inline int wvif_count(struct wfx_dev *wdev)
125 {
126 	int i;
127 	int ret = 0;
128 	struct wfx_vif *wvif;
129 
130 	for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
131 		wvif = wdev_to_wvif(wdev, i);
132 		if (wvif)
133 			ret++;
134 	}
135 	return ret;
136 }
137 
138 static inline void memreverse(u8 *src, u8 length)
139 {
140 	u8 *lo = src;
141 	u8 *hi = src + length - 1;
142 	u8 swap;
143 
144 	while (lo < hi) {
145 		swap = *lo;
146 		*lo++ = *hi;
147 		*hi-- = swap;
148 	}
149 }
150 
151 static inline int memzcmp(void *src, unsigned int size)
152 {
153 	u8 *buf = src;
154 
155 	if (!size)
156 		return 0;
157 	if (*buf)
158 		return 1;
159 	return memcmp(buf, buf + 1, size - 1);
160 }
161 
162 #endif
163