1 /******************************************************************************
2 *
3 * Copyright(c) 2019 - 2021 Realtek Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 *****************************************************************************/
15 #define _HAL_API_MAC_C_
16 #include "mac/mac_ax.h"
17 #include "hal_headers.h"
18 #ifdef RTW_PHL_BCN
19 #include "mac/mac_ax/fwcmd.h"
20 #endif
21
22 #define RTL8852A_FPGA_VERIFICATION 1
23
hal_mac_get_macid_num(struct hal_info_t * hal)24 u16 hal_mac_get_macid_num(struct hal_info_t *hal)
25 {
26 struct mac_ax_adapter *mac = hal_to_mac(hal);
27
28 return mac->hw_info->macid_num;
29 }
hal_mac_get_hwinfo(struct hal_info_t * hal,struct hal_spec_t * hal_spec)30 void hal_mac_get_hwinfo(struct hal_info_t *hal, struct hal_spec_t *hal_spec)
31 {
32 struct mac_ax_adapter *mac = hal_to_mac(hal);
33 struct mac_ax_hw_info *mac_info = mac->hw_info;
34 struct mac_ax_ops *ops = mac->ops;
35 /*struct mac_ax_hw_info* (*get_hw_info)(struct mac_ax_adapter *adapter);*/
36
37 mac_info = ops->get_hw_info(mac);
38
39 hal_spec->macid_num = mac_info->macid_num;
40
41 hal->hal_com->cv = mac_info->cv;
42 PHL_INFO("[MAC-INFO]- CV : %d\n", mac_info->cv);
43 PHL_INFO("[MAC-INFO]- tx_ch_num: %d\n", mac_info->tx_ch_num);
44
45 PHL_INFO("[MAC-INFO]- tx_data_ch_num: %d\n", mac_info->tx_data_ch_num);
46 PHL_INFO("[MAC-INFO]- wd_body_len: %d\n", mac_info->wd_body_len);
47 PHL_INFO("[MAC-INFO]- wd_info_len: %d\n", mac_info->wd_info_len);
48
49 PHL_INFO("[MAC-INFO]- pwr_seq_ver: %d\n", mac_info->pwr_seq_ver);
50 PHL_INFO("[MAC-INFO]- fifo_size: %d\n", mac_info->fifo_size);
51 PHL_INFO("[MAC-INFO]- macid_num: %d\n", mac_info->macid_num);
52 PHL_INFO("[MAC-INFO]- wl_efuse_size: %d\n", mac_info->wl_efuse_size);
53
54 PHL_INFO("[MAC-INFO]- efuse_size: %d\n", mac_info->efuse_size);
55 PHL_INFO("[MAC-INFO]- log_efuse_size: %d\n", mac_info->log_efuse_size);
56
57 PHL_INFO("[MAC-INFO]- bt_efuse_size: %d\n", mac_info->bt_efuse_size);
58 PHL_INFO("[MAC-INFO]- sec_ctrl_efuse_size: %d\n", mac_info->sec_ctrl_efuse_size);
59 PHL_INFO("[MAC-INFO]- sec_data_efuse_size: %d\n", mac_info->sec_data_efuse_size);
60
61 }
62
rtw_hal_mac_watchdog(struct hal_info_t * hal_info)63 enum rtw_hal_status rtw_hal_mac_watchdog(struct hal_info_t *hal_info)
64 {
65 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
66 u32 ret = 0;
67
68 ret = mac->ops->watchdog(mac);
69
70 return (ret == MACSUCCESS) ? (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
71 }
72
73 #ifdef CONFIG_PCI_HCI
rtw_hal_mac_set_pcicfg(struct hal_info_t * hal_info,struct mac_ax_pcie_cfgspc_param * pci_cfgspc)74 enum rtw_hal_status rtw_hal_mac_set_pcicfg(struct hal_info_t *hal_info,
75 struct mac_ax_pcie_cfgspc_param *pci_cfgspc)
76 {
77 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
78 u32 ret = 0;
79
80 ret = mac->ops->set_hw_value(mac, MAC_AX_HW_PCIE_CFGSPC_SET, pci_cfgspc);
81 return (ret == 0) ? (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
82 }
83
rtw_hal_mac_ltr_sw_trigger(struct hal_info_t * hal_info,enum rtw_pcie_ltr_state state)84 enum rtw_hal_status rtw_hal_mac_ltr_sw_trigger(struct hal_info_t *hal_info, enum rtw_pcie_ltr_state state)
85 {
86 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
87 enum mac_ax_pcie_ltr_sw_ctrl ctrl;
88 enum rtw_hal_status hstats = RTW_HAL_STATUS_FAILURE;
89 u32 ret = 0;
90
91 switch (state) {
92
93 case RTW_PCIE_LTR_SW_ACT:
94 ctrl = MAC_AX_PCIE_LTR_SW_ACT;
95 break;
96 case RTW_PCIE_LTR_SW_IDLE:
97 ctrl = MAC_AX_PCIE_LTR_SW_IDLE;
98 break;
99 default:
100 PHL_INFO("%s: state = %u, fail to trigger \n", __func__, state);
101 return RTW_HAL_STATUS_FAILURE;
102
103 }
104
105 ret = mac->ops->set_hw_value(mac, MAX_AX_HW_PCIE_LTR_SW_TRIGGER, &ctrl);
106
107 if (ret == 0)
108 hstats = RTW_HAL_STATUS_SUCCESS;
109 else
110 hstats = RTW_HAL_STATUS_FAILURE;
111
112 return hstats;
113 }
114
rtw_hal_mac_ltr_set_pcie(struct hal_info_t * hal_info,enum rtw_pcie_bus_func_cap_t hw_ctrl,u8 idle_ctrl,u32 idle_val,u8 act_ctrl,u32 act_val)115 enum rtw_hal_status rtw_hal_mac_ltr_set_pcie(struct hal_info_t *hal_info,
116 enum rtw_pcie_bus_func_cap_t hw_ctrl,
117 u8 idle_ctrl, u32 idle_val, u8 act_ctrl, u32 act_val)
118 {
119 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
120 struct mac_ax_pcie_ltr_param param;
121 u32 ret = 0;
122 enum mac_ax_pcie_func_ctrl ctrl;
123
124 switch (hw_ctrl) {
125
126 case RTW_PCIE_BUS_FUNC_ENABLE:
127 ctrl = MAC_AX_PCIE_ENABLE;
128 break;
129 case RTW_PCIE_BUS_FUNC_DISABLE:
130 ctrl = MAC_AX_PCIE_DISABLE;
131 break;
132 case RTW_PCIE_BUS_FUNC_DEFAULT:
133 ctrl = MAC_AX_PCIE_DEFAULT;
134 break;
135 default:
136 ctrl = MAC_AX_PCIE_IGNORE;
137 }
138
139 param.write = 1;
140 param.read = 0;
141 param.ltr_ctrl = MAC_AX_PCIE_IGNORE;
142 param.ltr_hw_ctrl = ctrl;
143 param.ltr_spc_ctrl = MAC_AX_PCIE_LTR_SPC_IGNORE;
144 param.ltr_idle_timer_ctrl = MAC_AX_PCIE_LTR_IDLE_TIMER_IGNORE;
145 param.ltr_rx0_th_ctrl.ctrl = MAC_AX_PCIE_IGNORE;
146 param.ltr_rx0_th_ctrl.val = 0;
147 param.ltr_rx1_th_ctrl.ctrl = MAC_AX_PCIE_IGNORE;
148 param.ltr_rx1_th_ctrl.val = 0;
149
150 /* when ctrl is not equal to 0, setting ignore to make hw control the value */
151 if (idle_ctrl) {
152 param.ltr_idle_lat_ctrl.ctrl = MAC_AX_PCIE_ENABLE;
153 param.ltr_idle_lat_ctrl.val = idle_val;
154 } else {
155 param.ltr_idle_lat_ctrl.ctrl = MAC_AX_PCIE_IGNORE;
156 param.ltr_idle_lat_ctrl.val = 0;
157 }
158
159 if (act_ctrl) {
160 param.ltr_act_lat_ctrl.ctrl = MAC_AX_PCIE_ENABLE;
161 param.ltr_act_lat_ctrl.val = act_val;
162 } else {
163 param.ltr_act_lat_ctrl.ctrl = MAC_AX_PCIE_IGNORE;
164 param.ltr_act_lat_ctrl.val = 0;
165 }
166
167 PHL_INFO("%s: ltr_hw_ctrl %u \n", __func__, param.ltr_hw_ctrl);
168 PHL_INFO("%s: ltr_idle_lat_ctrl, ctrl %u, val %u\n", __func__,
169 param.ltr_idle_lat_ctrl.ctrl, param.ltr_idle_lat_ctrl.val);
170 PHL_INFO("%s: ltr_act_lat_ctrl, ctrl %u, val %u\n", __func__,
171 param.ltr_act_lat_ctrl.ctrl, param.ltr_act_lat_ctrl.val);
172
173
174 ret = mac->ops->intf_ops->ltr_set_pcie(mac, ¶m);
175 return (ret == 0) ? (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
176 }
177
hal_mac_set_l2_leave(struct hal_info_t * hal_info)178 enum rtw_hal_status hal_mac_set_l2_leave(struct hal_info_t *hal_info)
179 {
180 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
181 u32 ret = 0;
182 u8 set = true;
183
184 ret = mac->ops->set_hw_value(mac, MAX_AX_HW_PCIE_L2_LEAVE, &set);
185 return (ret == MACSUCCESS) ? (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
186 }
187
rtw_hal_mac_poll_txdma_idle(struct hal_info_t * hal,struct mac_ax_txdma_ch_map * ch_map)188 enum rtw_hal_status rtw_hal_mac_poll_txdma_idle(struct hal_info_t *hal,
189 struct mac_ax_txdma_ch_map *ch_map)
190 {
191
192 struct mac_ax_adapter *mac = hal_to_mac(hal);
193 struct mac_ax_ops *hal_mac_ops = mac->ops;
194 u32 ret = 0;
195
196 ret = hal_mac_ops->intf_ops->poll_txdma_ch_idle(mac, ch_map);
197
198 return (ret == MACSUCCESS) ?
199 (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
200
201 }
202
rtw_hal_mac_poll_rxdma_idle(struct hal_info_t * hal,struct mac_ax_rxdma_ch_map * ch_map)203 enum rtw_hal_status rtw_hal_mac_poll_rxdma_idle(struct hal_info_t *hal,
204 struct mac_ax_rxdma_ch_map *ch_map)
205 {
206 struct mac_ax_adapter *mac = hal_to_mac(hal);
207 struct mac_ax_ops *hal_mac_ops = mac->ops;
208 u32 ret = 0;
209
210 ret = hal_mac_ops->intf_ops->poll_rxdma_ch_idle(mac, ch_map);
211
212 return (ret == MACSUCCESS) ?
213 (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
214 }
rtw_hal_mac_cfg_txdma(struct hal_info_t * hal,struct mac_ax_txdma_ch_map * ch_map)215 enum rtw_hal_status rtw_hal_mac_cfg_txdma(struct hal_info_t *hal,
216 struct mac_ax_txdma_ch_map *ch_map)
217 {
218 struct mac_ax_adapter *mac = hal_to_mac(hal);
219 struct mac_ax_ops *hal_mac_ops = mac->ops;
220 u32 ret = 0;
221
222 ret = hal_mac_ops->intf_ops->ctrl_txdma_ch(mac, ch_map);
223
224 return (ret == MACSUCCESS) ?
225 (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
226
227 }
228
229
rtw_hal_mac_clr_bdidx(struct hal_info_t * hal)230 enum rtw_hal_status rtw_hal_mac_clr_bdidx(struct hal_info_t *hal)
231 {
232 struct mac_ax_adapter *mac = hal_to_mac(hal);
233 struct mac_ax_ops *hal_mac_ops = mac->ops;
234 u32 ret = 0;
235
236 ret = hal_mac_ops->intf_ops->clr_idx_all(mac);
237
238 return (ret == MACSUCCESS) ?
239 (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
240 }
241
rtw_hal_mac_rst_bdram(struct hal_info_t * hal)242 enum rtw_hal_status rtw_hal_mac_rst_bdram(struct hal_info_t *hal)
243 {
244 struct mac_ax_adapter *mac = hal_to_mac(hal);
245 struct mac_ax_ops *hal_mac_ops = mac->ops;
246 u32 ret = 0;
247 u8 val;
248
249 ret = hal_mac_ops->set_hw_value(mac, MAC_AX_HW_PCIE_RST_BDRAM, &val);
250
251 return (ret == MACSUCCESS) ?
252 (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
253 }
254
rtw_hal_mac_cfg_dma_io(struct hal_info_t * hal,u8 en)255 enum rtw_hal_status rtw_hal_mac_cfg_dma_io(struct hal_info_t *hal, u8 en)
256 {
257 struct mac_ax_adapter *mac = hal_to_mac(hal);
258 struct mac_ax_ops *hal_mac_ops = mac->ops;
259 enum mac_ax_func_sw ctrl;
260 u32 ret = 0;
261
262 if (en)
263 ctrl = MAC_AX_FUNC_EN;
264 else
265 ctrl = MAC_AX_FUNC_DIS;
266
267 ret = hal_mac_ops->intf_ops->ctrl_dma_io(mac, ctrl);
268
269 return (ret == MACSUCCESS) ?
270 (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
271 }
272
273
274 #endif
275
276 #ifdef CONFIG_USB_HCI
hal_mac_get_bulkout_id(struct hal_info_t * hal,u8 dma_ch,u8 mode)277 u8 hal_mac_get_bulkout_id(struct hal_info_t *hal, u8 dma_ch, u8 mode)
278 {
279 struct mac_ax_adapter *mac = hal_to_mac(hal);
280
281 return mac->ops->intf_ops->get_bulkout_id(mac, dma_ch, mode);
282 }
283
hal_mac_usb_tx_agg_cfg(struct hal_info_t * hal,u8 * wd_buf,u8 agg_num)284 u32 hal_mac_usb_tx_agg_cfg(struct hal_info_t *hal, u8* wd_buf, u8 agg_num)
285 {
286 struct mac_ax_adapter *mac = hal_to_mac(hal);
287 struct mac_ax_usb_tx_agg_cfg agg;
288
289 agg.pkt = wd_buf;
290 agg.agg_num = agg_num;
291
292 return mac->ops->intf_ops->usb_tx_agg_cfg(mac, &agg);
293 }
294
hal_mac_usb_rx_agg_cfg(struct hal_info_t * hal,u8 agg_mode,u8 drv_define,u8 timeout,u8 size,u8 pkt_num)295 u32 hal_mac_usb_rx_agg_cfg(struct hal_info_t *hal, u8 agg_mode,
296 u8 drv_define, u8 timeout, u8 size, u8 pkt_num)
297 {
298 struct mac_ax_adapter *mac = hal_to_mac(hal);
299 struct mac_ax_rx_agg_cfg cfg;
300
301 cfg.mode = agg_mode;
302 cfg.thold.drv_define = drv_define;
303 cfg.thold.timeout = timeout;
304 cfg.thold.size = size;
305 cfg.thold.pkt_num = pkt_num;
306
307 return mac->ops->intf_ops->usb_rx_agg_cfg(mac, &cfg);
308 }
309
hal_mac_force_usb_switch(struct hal_info_t * hal)310 enum rtw_hal_status hal_mac_force_usb_switch(struct hal_info_t *hal)
311 {
312 struct mac_ax_adapter *mac = hal_to_mac(hal);
313
314 if(mac->ops->intf_ops->u2u3_switch(mac) == MACSUCCESS) {
315 PHL_INFO("%s,success!\n", __func__);
316 return RTW_HAL_STATUS_SUCCESS;
317 }
318 else {
319 PHL_INFO("%s,fail!\n", __func__);
320 return RTW_HAL_STATUS_FAILURE;
321 }
322 }
323
hal_mac_get_cur_usb_mode(struct hal_info_t * hal)324 u32 hal_mac_get_cur_usb_mode(struct hal_info_t *hal)
325 {
326 struct mac_ax_adapter *mac = hal_to_mac(hal);
327 return mac->ops->intf_ops->get_usb_mode(mac);
328 }
hal_mac_get_usb_support_ability(struct hal_info_t * hal)329 u32 hal_mac_get_usb_support_ability(struct hal_info_t *hal)
330
331 {
332
333 struct mac_ax_adapter *mac = hal_to_mac(hal);
334
335 return mac->ops->intf_ops->get_usb_support_ability(mac);
336
337 }
hal_mac_usb_get_max_bulkout_wd_num(struct hal_info_t * hal)338 u8 hal_mac_usb_get_max_bulkout_wd_num(struct hal_info_t *hal)
339 {
340 struct mac_ax_adapter *mac = hal_to_mac(hal);
341
342 return mac->usb_info.max_bulkout_wd_num;
343 }
344 #endif
345
346 #ifdef CONFIG_SDIO_HCI
hal_mac_sdio_read8(struct rtw_hal_com_t * hal,u32 addr)347 u8 hal_mac_sdio_read8(struct rtw_hal_com_t *hal, u32 addr)
348 {
349 struct hal_info_t *hal_info = hal->hal_priv;
350 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
351 struct mac_ax_ops *mac_api = mac->ops;
352 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
353
354 return mac_intf_ops->reg_read8(mac, addr);
355 }
356
hal_mac_sdio_read16(struct rtw_hal_com_t * hal,u32 addr)357 u16 hal_mac_sdio_read16(struct rtw_hal_com_t *hal, u32 addr)
358 {
359 struct hal_info_t *hal_info = hal->hal_priv;
360 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
361 struct mac_ax_ops *mac_api = mac->ops;
362 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
363
364 return mac_intf_ops->reg_read16(mac, addr);
365 }
366
hal_mac_sdio_read32(struct rtw_hal_com_t * hal,u32 addr)367 u32 hal_mac_sdio_read32(struct rtw_hal_com_t *hal, u32 addr)
368 {
369 struct hal_info_t *hal_info = hal->hal_priv;
370 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
371 struct mac_ax_ops *mac_api = mac->ops;
372 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
373
374 return mac_intf_ops->reg_read32(mac, addr);
375 }
376
hal_mac_sdio_write8(struct rtw_hal_com_t * hal,u32 addr,u8 value)377 int hal_mac_sdio_write8(struct rtw_hal_com_t *hal, u32 addr, u8 value)
378 {
379 struct hal_info_t *hal_info = hal->hal_priv;
380 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
381 struct mac_ax_ops *mac_api = mac->ops;
382 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
383
384 mac_intf_ops->reg_write8(mac, addr, value);
385 return 0;
386 }
387
hal_mac_sdio_write16(struct rtw_hal_com_t * hal,u32 addr,u16 value)388 int hal_mac_sdio_write16(struct rtw_hal_com_t *hal, u32 addr, u16 value)
389 {
390 struct hal_info_t *hal_info = hal->hal_priv;
391 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
392 struct mac_ax_ops *mac_api = mac->ops;
393 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
394
395 mac_intf_ops->reg_write16(mac, addr, value);
396 return 0;
397 }
398
hal_mac_sdio_write32(struct rtw_hal_com_t * hal,u32 addr,u32 value)399 int hal_mac_sdio_write32(struct rtw_hal_com_t *hal, u32 addr, u32 value)
400 {
401 struct hal_info_t *hal_info = hal->hal_priv;
402 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
403 struct mac_ax_ops *mac_api = mac->ops;
404 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
405
406 mac_intf_ops->reg_write32(mac, addr, value);
407 return 0;
408 }
409
_read_register(struct rtw_hal_com_t * hal,u32 addr,u32 cnt,u8 * buf)410 static void _read_register(struct rtw_hal_com_t *hal, u32 addr, u32 cnt, u8 *buf)
411 {
412 u32 i, n;
413 u16 val16;
414 u32 val32;
415
416 i = addr & 0x3;
417 /* Handle address not start from 4 bytes alignment case */
418 if (i) {
419 val32 = cpu_to_le32(hal_read32(hal, addr & ~0x3));
420 n = 4 - i;
421 _os_mem_cpy(hal->drv_priv, buf, ((u8 *)&val32) + i, n);
422 i = n;
423 cnt -= n;
424 }
425
426 while (cnt) {
427 if (cnt >= 4)
428 n = 4;
429 else if (cnt >= 2)
430 n = 2;
431 else
432 n = 1;
433 cnt -= n;
434
435 switch (n) {
436 case 1:
437 buf[i] = hal_read8(hal, addr+i);
438 i++;
439 break;
440 case 2:
441 val16 = cpu_to_le16(hal_read16(hal, addr+i));
442 _os_mem_cpy(hal->drv_priv, &buf[i], &val16, 2);
443 i += 2;
444 break;
445 case 4:
446 val32 = cpu_to_le32(hal_read32(hal, addr+i));
447 _os_mem_cpy(hal->drv_priv, &buf[i], &val32, 4);
448 i += 4;
449 break;
450 }
451 }
452 }
453
_sdio_read_local(struct rtw_hal_com_t * hal,u32 addr,u32 cnt,u8 * buf)454 static int _sdio_read_local(struct rtw_hal_com_t *hal, u32 addr, u32 cnt, u8 *buf)
455 {
456 /*struct hal_info_t *hal_info = hal->hal_priv;*/
457 /*struct mac_ax_adapter *mac = hal_to_mac(hal_info);*/
458 /*struct mac_ax_ops *mac_api = mac->ops;*/
459 /*struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;*/
460
461 if (buf == NULL)
462 return -1;
463 /*GEORGIA_TODO_FIXIT_ASKFORMAC*/
464 /*mac_intf_ops->reg_readrn(mac, addr, cnt, buf);*/
465 return 0;
466 }
467
hal_mac_sdio_read_mem(struct rtw_hal_com_t * hal,u32 addr,u32 cnt,u8 * pmem)468 void hal_mac_sdio_read_mem(struct rtw_hal_com_t *hal, u32 addr, u32 cnt, u8 *pmem)
469 {
470
471 if (pmem == NULL) {
472 PHL_ERR("pmem is NULL\n");
473 return;
474 }
475
476 if (addr & 0xFFFF0000) {
477 int err = 0;
478
479 err = _sdio_read_local(hal, addr, cnt, pmem);
480 if (!err)
481 return;
482 }
483 _read_register(hal, addr, cnt, pmem);
484 }
485
486 #ifdef CONFIG_SDIO_INDIRECT_ACCESS
hal_mac_sdio_iread8(struct rtw_hal_com_t * hal,u32 addr)487 u8 hal_mac_sdio_iread8(struct rtw_hal_com_t *hal, u32 addr)
488 {
489 struct hal_info_t *hal_info = hal->hal_priv;
490 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
491 struct mac_ax_ops *mac_api = mac->ops;
492 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
493
494 return mac_intf_ops->reg_read8(mac, addr);
495 }
496
hal_mac_sdio_iread16(struct rtw_hal_com_t * hal,u32 addr)497 u16 hal_mac_sdio_iread16(struct rtw_hal_com_t *hal, u32 addr)
498 {
499 struct hal_info_t *hal_info = hal->hal_priv;
500 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
501 struct mac_ax_ops *mac_api = mac->ops;
502 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
503
504 return mac_intf_ops->reg_read16(mac, addr);
505 }
506
hal_mac_sdio_iread32(struct rtw_hal_com_t * hal,u32 addr)507 u32 hal_mac_sdio_iread32(struct rtw_hal_com_t *hal, u32 addr)
508 {
509 struct hal_info_t *hal_info = hal->hal_priv;
510 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
511 struct mac_ax_ops *mac_api = mac->ops;
512 struct mac_ax_intf_ops *mac_intf_ops = mac_api->intf_ops;
513
514 return 0;
515 }
516 #endif /* CONFIG_SDIO_INDIRECT_ACCESS */
517 #endif /* CONFIG_SDIO_HCI */
518
519
520 #ifndef CONFIG_NEW_HALMAC_INTERFACE
521 #ifdef CONFIG_SDIO_HCI
hal_mac_sdio_cmd52_r8(void * h,u32 addr)522 static u8 hal_mac_sdio_cmd52_r8(void *h, u32 addr)
523 {
524 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
525
526 return _os_sdio_cmd52_r8(hal->drv_priv, addr);
527 }
hal_mac_sdio_cmd53_r8(void * h,u32 addr)528 static u8 hal_mac_sdio_cmd53_r8(void *h, u32 addr)
529 {
530 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
531
532 return _os_sdio_cmd53_r8(hal->drv_priv, addr);
533 }
hal_mac_sdio_cmd53_r16(void * h,u32 addr)534 static u16 hal_mac_sdio_cmd53_r16(void *h, u32 addr)
535 {
536 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
537
538 return _os_sdio_cmd53_r16(hal->drv_priv, addr);
539 }
hal_mac_sdio_cmd53_r32(void * h,u32 addr)540 static u32 hal_mac_sdio_cmd53_r32(void *h, u32 addr)
541 {
542 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
543
544 return _os_sdio_cmd53_r32(hal->drv_priv, addr);
545 }
hal_mac_sdio_cmd53_rn(void * h,u32 addr,u32 size,u8 * val)546 static u8 hal_mac_sdio_cmd53_rn(void *h, u32 addr, u32 size, u8 *val)
547 {
548 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
549
550 return _os_sdio_cmd53_rn(hal->drv_priv, addr, size,val);
551 }
hal_mac_sdio_cmd52_w8(void * h,u32 addr,u8 val)552 static void hal_mac_sdio_cmd52_w8(void *h, u32 addr, u8 val)
553 {
554 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
555
556 _os_sdio_cmd52_w8(hal->drv_priv, addr, val);
557 }
hal_mac_sdio_cmd53_w8(void * h,u32 addr,u8 val)558 static void hal_mac_sdio_cmd53_w8(void *h, u32 addr, u8 val)
559 {
560 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
561
562 _os_sdio_cmd53_w8(hal->drv_priv, addr, val);
563 }
hal_mac_sdio_cmd53_w16(void * h,u32 addr,u16 val)564 static void hal_mac_sdio_cmd53_w16(void *h, u32 addr, u16 val)
565 {
566 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
567
568 _os_sdio_cmd53_w16(hal->drv_priv, addr, val);
569 }
hal_mac_sdio_cmd53_w32(void * h,u32 addr,u32 val)570 static void hal_mac_sdio_cmd53_w32(void *h, u32 addr, u32 val)
571 {
572 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
573
574 _os_sdio_cmd53_w32(hal->drv_priv, addr, val);
575 }
hal_mac_sdio_cmd53_wn(void * h,u32 addr,u32 size,u8 * val)576 static u8 hal_mac_sdio_cmd53_wn(void *h, u32 addr, u32 size, u8 *val)
577 {
578 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
579
580 _os_sdio_cmd53_wn(hal->drv_priv, addr, size, val);
581 return true;
582 }
hal_mac_sdio_cmd52_cia_r8(void * h,u32 addr)583 static u8 hal_mac_sdio_cmd52_cia_r8(void *h, u32 addr)
584 {
585 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
586
587 return _os_sdio_read_cia_r8(hal->drv_priv, addr);
588 }
589 #endif /*CONFIG_SDIO_HCI*/
590
hal_mac_reg_r8(void * h,u32 addr)591 static u8 hal_mac_reg_r8(void *h, u32 addr)
592 {
593 return hal_read8((struct rtw_hal_com_t *)h, addr);
594 }
hal_mac_reg_r16(void * h,u32 addr)595 static u16 hal_mac_reg_r16(void *h, u32 addr)
596 {
597 return hal_read16((struct rtw_hal_com_t *)h, addr);
598 }
hal_mac_reg_r32(void * h,u32 addr)599 static u32 hal_mac_reg_r32(void *h, u32 addr)
600 {
601 return hal_read32((struct rtw_hal_com_t *)h, addr);
602 }
hal_mac_reg_w8(void * h,u32 addr,u8 val)603 static void hal_mac_reg_w8(void *h, u32 addr, u8 val)
604 {
605 hal_write8((struct rtw_hal_com_t *)h, addr, val);
606 }
hal_mac_reg_w16(void * h,u32 addr,u16 val)607 static void hal_mac_reg_w16(void *h, u32 addr, u16 val)
608 {
609 hal_write16((struct rtw_hal_com_t *)h, addr, val);
610 }
hal_mac_reg_w32(void * h,u32 addr,u32 val)611 static void hal_mac_reg_w32(void *h, u32 addr, u32 val)
612 {
613 hal_write32((struct rtw_hal_com_t *)h, addr, val);
614 }
615
616
617 #ifdef DBG_HAL_MAC_MEM_MOINTOR
hal_mac_mem_free(void * h,void * buf,u32 size)618 static void hal_mac_mem_free(void *h, void *buf, u32 size)
619 {
620 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
621
622 /*PHL_INFO("MAC free mem - :%d\n", size);*/
623 _os_atomic_sub(hal->drv_priv, &(hal->hal_mac_mem), size);
624 _os_mem_free(hal->drv_priv, buf, size);
625 }
hal_mac_mem_alloc(void * h,u32 size)626 static void* hal_mac_mem_alloc(void *h, u32 size)
627 {
628 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
629
630 /*PHL_INFO("MAC Alloc mem - :%d\n", size);*/
631 _os_atomic_add_return(hal->drv_priv, &(hal->hal_mac_mem), size);
632
633 return _os_mem_alloc(hal->drv_priv, size);
634 }
635 #else
hal_mac_mem_free(void * h,void * buf,u32 size)636 static void hal_mac_mem_free(void *h, void *buf, u32 size)
637 {
638 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
639
640 _os_mem_free(hal->drv_priv, buf, size);
641 }
hal_mac_mem_alloc(void * h,u32 size)642 static void* hal_mac_mem_alloc(void *h, u32 size)
643 {
644 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
645
646 return _os_mem_alloc(hal->drv_priv, size);
647 }
648 #endif /*DBG_HAL_MAC_MEM_MOINTOR*/
hal_mac_mem_cpy(void * h,void * dest,void * src,u32 size)649 static void hal_mac_mem_cpy(void *h, void *dest, void *src, u32 size)
650 {
651 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
652
653 _os_mem_cpy(hal->drv_priv, dest, src, size);
654 }
hal_mac_mem_set(void * h,void * addr,u8 val,u32 size)655 static void hal_mac_mem_set(void *h, void *addr, u8 val, u32 size)
656 {
657 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
658
659 _os_mem_set(hal->drv_priv, addr, val, size);
660
661 }
hal_mac_mem_cmp(void * h,void * ptr1,void * ptr2,u32 num)662 static s32 hal_mac_mem_cmp(void *h, void *ptr1, void *ptr2, u32 num)
663 {
664 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
665
666 return _os_mem_cmp(hal->drv_priv, ptr1, ptr2, num);
667 }
hal_mac_udelay(void * h,u32 us)668 static void hal_mac_udelay(void *h, u32 us)
669 {
670 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
671
672 _os_delay_us(hal->drv_priv, us);
673 }
hal_mac_mdelay(void * h,u32 ms)674 static void hal_mac_mdelay(void *h, u32 ms)
675 {
676 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
677
678 _os_delay_ms(hal->drv_priv, ms);
679 }
680
hal_mac_mutex_init(void * h,mac_ax_mutex * mutex)681 static void hal_mac_mutex_init(void *h, mac_ax_mutex *mutex)
682 {
683 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
684
685 _os_mutex_init(hal->drv_priv, mutex);
686 }
hal_mac_mutex_deinit(void * h,mac_ax_mutex * mutex)687 static void hal_mac_mutex_deinit(void *h, mac_ax_mutex *mutex)
688 {
689 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
690
691 _os_mutex_deinit(hal->drv_priv, mutex);
692 }
hal_mac_mutex_lock(void * h,mac_ax_mutex * mutex)693 static void hal_mac_mutex_lock(void *h, mac_ax_mutex *mutex)
694 {
695 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
696
697 _os_mutex_lock(hal->drv_priv, mutex);
698 }
hal_mac_mutex_unlock(void * h,mac_ax_mutex * mutex)699 static void hal_mac_mutex_unlock(void *h, mac_ax_mutex *mutex)
700 {
701 struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
702
703 _os_mutex_unlock(hal->drv_priv, mutex);
704 }
705
hal_mac_event_notify(void * h,enum mac_ax_feature mac_ft,enum mac_ax_status stat,u8 * buf,u32 size)706 static void hal_mac_event_notify(void *h,
707 enum mac_ax_feature mac_ft,
708 enum mac_ax_status stat, u8 *buf, u32 size)
709 {
710 //struct rtw_hal_com_t *hal = (struct rtw_hal_com_t *)h;
711
712 }
713
hal_query_h2c_pkt(struct rtw_phl_com_t * phl_com,struct rtw_hal_com_t * hal_com,enum h2c_buf_class type)714 struct rtw_h2c_pkt *hal_query_h2c_pkt(struct rtw_phl_com_t *phl_com,
715 struct rtw_hal_com_t *hal_com,
716 enum h2c_buf_class type)
717 {
718 struct rtw_h2c_pkt *h2c_pkt = NULL;
719 enum rtw_h2c_pkt_type pkt_type = H2CB_TYPE_MAX;
720
721 switch (type) {
722 case H2CB_CLASS_CMD:
723 pkt_type = H2CB_TYPE_CMD;
724 break;
725 case H2CB_CLASS_DATA:
726 pkt_type = H2CB_TYPE_DATA;
727 break;
728 case H2CB_CLASS_LONG_DATA:
729 pkt_type = H2CB_TYPE_LONG_DATA;
730 break;
731 case H2CB_CLASS_LAST:
732 pkt_type = H2CB_TYPE_MAX;
733 break;
734 default:
735 PHL_ERR("%s: Unknown type(%d)\n", __func__, type);
736 break;
737 }
738
739 h2c_pkt = rtw_phl_query_h2c_pkt(phl_com, pkt_type);
740
741 if (!h2c_pkt)
742 PHL_ERR("hal_query_h2c_pkt fail (type %d).\n", type);
743
744 return h2c_pkt;
745 }
746
hal_pltfm_tx(struct rtw_phl_com_t * phl_com,struct rtw_hal_com_t * hal_com,struct rtw_h2c_pkt * pkt)747 enum rtw_hal_status hal_pltfm_tx(struct rtw_phl_com_t *phl_com,
748 struct rtw_hal_com_t *hal_com,
749 struct rtw_h2c_pkt *pkt)
750 {
751 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
752
753 if (rtw_phl_pltfm_tx(phl_com, pkt) == RTW_PHL_STATUS_SUCCESS)
754 hstatus = RTW_HAL_STATUS_SUCCESS;
755 else
756 PHL_ERR("hal_pltfm_tx fail.\n");
757
758 return hstatus;
759 }
760
hal_ser_l2_notify(void * phl,void * hal)761 void hal_ser_l2_notify(void *phl, void *hal)
762 {
763 struct rtw_phl_com_t *phl_com = (struct rtw_phl_com_t *)phl;
764
765 rtw_phl_ser_l2_notify(phl_com);
766 }
767
hal_mac_sprintf(void * drv_adapter,char * buf,size_t size,const char * fmt,...)768 static s32 hal_mac_sprintf(void *drv_adapter, char *buf, size_t size, const char *fmt, ...)
769 {
770 #if defined(PHL_PLATFORM_LINUX) || defined(PHL_PLATFORM_WINDOWS)
771 s32 ret;
772 va_list args;
773
774 va_start(args, fmt);
775 ret = _os_vsnprintf(buf, size, fmt, args);
776 if (ret >= 0)
777 ret = _os_strlen((u8 *)buf);
778
779 /* PHL_PRINT("[HAL_MMAC]%s", buf); */
780 va_end(args);
781 return ret;
782 #else
783 return 0;
784 #endif
785 }
786
hal_mac_strcmp(void * drv_adapter,const char * s1,const char * s2)787 static s32 hal_mac_strcmp(void *drv_adapter, const char *s1, const char *s2)
788 {
789 return _os_strcmp(s1, s2);
790 }
791
hal_mac_strsep(void * drv_adapter,char ** s,const char * ct)792 static char* hal_mac_strsep(void *drv_adapter, char **s, const char *ct)
793 {
794 return _os_strsep(s, ct);
795 }
796
hal_mac_strlen(void * drv_adapter,char * buf)797 static u32 hal_mac_strlen(void *drv_adapter, char *buf)
798 {
799 return _os_strlen((u8 *)buf);
800 }
801
hal_mac_strcpy(void * drv_adapter,char * dest,const char * src)802 static char* hal_mac_strcpy(void *drv_adapter, char *dest, const char *src)
803 {
804 return _os_strcpy(dest, src);
805 }
806
hal_mac_strpbrk(void * drv_adapter,const char * cs,const char * ct)807 static char* hal_mac_strpbrk(void *drv_adapter, const char *cs, const char *ct)
808 {
809 return _os_strpbrk(cs, ct);
810 }
811
hal_mac_strtoul(void * drv_adapter,const char * buf,u32 base)812 static u32 hal_mac_strtoul(void *drv_adapter, const char *buf, u32 base)
813 {
814 #if 1
815 u32 ret = 0, val = 0;
816
817 if (base == 10)
818 ret = _os_sscanf(buf, "%d", &val);
819 else if (base == 16)
820 ret = _os_sscanf(buf, "%x", &val);
821 else
822 ret = _os_sscanf(buf, "%d", &val);
823
824 return val;
825 #else
826 //stdlib strtoul
827 #endif
828
829 }
830
831 static u8
hal_mac_ld_fw_symbol(void * phl_com,void * hal_com,const char * name,u8 ** buf,u32 * buf_size)832 hal_mac_ld_fw_symbol(void *phl_com, void *hal_com, const char *name,
833 u8 **buf, u32 *buf_size)
834 {
835 return rtw_hal_ld_fw_symbol((struct rtw_phl_com_t *)phl_com,
836 (struct rtw_hal_com_t *)hal_com, name, buf, buf_size);
837 }
838
839 #define RTW_HALMAC_FAIL 0
840 #define RTW_HALMAC_SUCCESS 1
841 #define MSG_PREFIX "[MAC]"
842
hal_mac_msg_print(void * p,u8 dbg_level,s8 * fmt,...)843 void hal_mac_msg_print(void *p, u8 dbg_level, s8 *fmt, ...)
844 {
845 #if defined(PHL_PLATFORM_LINUX) || defined(PHL_PLATFORM_WINDOWS)
846 #define MSG_LEN 100
847 va_list args;
848 char str[MSG_LEN] = {0};
849 int err;
850 u8 ret = RTW_HALMAC_SUCCESS;
851
852 str[0] = '\n';
853 va_start(args, fmt);
854 err = _os_vsnprintf(str, MSG_LEN, fmt, args);
855 va_end(args);
856
857 /* An output error is encountered */
858 if (err < 0)
859 return;
860 /* Output may be truncated due to size limit */
861 if ((err == (MSG_LEN - 1)) && (str[MSG_LEN - 2] != '\n'))
862 ret = RTW_HALMAC_FAIL;
863
864 PHL_TRACE(COMP_PHL_MAC, dbg_level, MSG_PREFIX " %s", str);
865 #endif
866 }
867
868 struct mac_ax_pltfm_cb rtw_plt_cb = {0};
rtw_plt_cb_init(void)869 void rtw_plt_cb_init(void)
870 {
871 /* R/W register */
872 #ifdef CONFIG_SDIO_HCI
873 rtw_plt_cb.sdio_cmd52_r8 = hal_mac_sdio_cmd52_r8;
874 rtw_plt_cb.sdio_cmd53_r8 = hal_mac_sdio_cmd53_r8;
875 rtw_plt_cb.sdio_cmd53_r16 = hal_mac_sdio_cmd53_r16;
876 rtw_plt_cb.sdio_cmd53_r32 = hal_mac_sdio_cmd53_r32;
877 rtw_plt_cb.sdio_cmd53_rn = hal_mac_sdio_cmd53_rn;
878 rtw_plt_cb.sdio_cmd52_w8 = hal_mac_sdio_cmd52_w8;
879 rtw_plt_cb.sdio_cmd53_w8 = hal_mac_sdio_cmd53_w8;
880 rtw_plt_cb.sdio_cmd53_w16 = hal_mac_sdio_cmd53_w16;
881 rtw_plt_cb.sdio_cmd53_w32 = hal_mac_sdio_cmd53_w32;
882 rtw_plt_cb.sdio_cmd53_wn = hal_mac_sdio_cmd53_wn;
883 rtw_plt_cb.sdio_cmd52_cia_r8 = hal_mac_sdio_cmd52_cia_r8;
884 #endif /* CONFIG_SDIO_HCI */
885
886 #if defined(CONFIG_USB_HCI) || defined(CONFIG_PCI_HCI)
887 rtw_plt_cb.reg_r8 = hal_mac_reg_r8;
888 rtw_plt_cb.reg_r16 = hal_mac_reg_r16;
889 rtw_plt_cb.reg_r32 = hal_mac_reg_r32;
890 rtw_plt_cb.reg_w8 = hal_mac_reg_w8;
891 rtw_plt_cb.reg_w16 = hal_mac_reg_w16;
892 rtw_plt_cb.reg_w32 = hal_mac_reg_w32;
893 #endif /* CONFIG_USB_HCI || CONFIG_PCI_HCI */
894
895 /* Memory allocate */
896 rtw_plt_cb.rtl_free = hal_mac_mem_free;
897 rtw_plt_cb.rtl_malloc = hal_mac_mem_alloc;
898 rtw_plt_cb.rtl_memcpy = hal_mac_mem_cpy;
899 rtw_plt_cb.rtl_memset = hal_mac_mem_set;
900 rtw_plt_cb.rtl_memcmp = hal_mac_mem_cmp;
901 /* Sleep */
902 rtw_plt_cb.rtl_delay_us = hal_mac_udelay;
903 rtw_plt_cb.rtl_delay_ms = hal_mac_mdelay;
904
905 /* Process Synchronization */
906 rtw_plt_cb.rtl_mutex_init = hal_mac_mutex_init;
907 rtw_plt_cb.rtl_mutex_deinit = hal_mac_mutex_deinit;
908 rtw_plt_cb.rtl_mutex_lock = hal_mac_mutex_lock;
909 rtw_plt_cb.rtl_mutex_unlock = hal_mac_mutex_unlock;
910
911 rtw_plt_cb.msg_print = hal_mac_msg_print;
912 rtw_plt_cb.event_notify = hal_mac_event_notify;
913 rtw_plt_cb.ser_l2_notify = hal_ser_l2_notify;
914 rtw_plt_cb.ld_fw_symbol = hal_mac_ld_fw_symbol;
915 /*.tx = ; */
916 #if MAC_AX_PHL_H2C
917 rtw_plt_cb.tx = hal_pltfm_tx;
918 rtw_plt_cb.rtl_query_h2c = hal_query_h2c_pkt;
919 #endif
920 #if MAC_AX_FEATURE_DBGCMD
921 rtw_plt_cb.rtl_sprintf = hal_mac_sprintf;
922 rtw_plt_cb.rtl_strcmp = hal_mac_strcmp;
923 rtw_plt_cb.rtl_strsep = hal_mac_strsep;
924 rtw_plt_cb.rtl_strlen = hal_mac_strlen;
925 rtw_plt_cb.rtl_strcpy = hal_mac_strcpy;
926 rtw_plt_cb.rtl_strpbrk = hal_mac_strpbrk;
927 rtw_plt_cb.rtl_strtoul = hal_mac_strtoul;
928 #endif
929 }
930
931
932 #endif /*CONFIG_NEW_HALMAC_INTERFACE*/
933
934 /* halmac wrapper API for hal and proto type is at hal_api_mac.h */
935 #define MAC_STATUS_MAX MACSDIOSEQERR+1 /* Wrong interface */
936 const char *const ma_status[] = {
937 "MAC Success",
938 "Callback of platform is null",
939 "Endian of platform error",
940 "Invalid base address",
941 "Leave suspend error",
942 "Pointer is null",
943 "Chip ID is undefined",
944 "Can not get MAC adapter",
945 "Unexpected structure alignment",
946 "Buffer space is not enough",
947 "Buffer size error",
948 "Invalid item",
949 "Polling timeout",
950 "Power switch fail",
951 "Work queue is busy",
952 "Failed compare result",
953 "Wrong interface",
954 "Incorrect FW bin file",
955 "Wrong FIFO configuration",
956 "Same MACID",
957 "MACID full",
958 "There is no FW",
959 "Process is busy",
960 "state machine error",
961 "switch efuse bank fail",
962 "read efuse fail",
963 "write efuse fail",
964 "efuse size error",
965 "eeprom parsing fail",
966 "compare efuse fail",
967 "secure on, no host indirect access",
968 "invalid tx dma channel",
969 "address cam update error",
970 "Power state error",
971 "SDIO Tx mix mode",
972 "SDIO Tx sequence error",
973 };
974
975 #define mac_sstr(status) (((status) >= MAC_STATUS_MAX) ? "unknown" : ma_status[(status)])
976
977 /**
978 * rtw_hal_mac_get_version() - Get HALMAC version
979 * @ver_str: string buffer for storing version string
980 * @len: string buffer length
981 *
982 * HALMAC version format is "V[major].[prototype].[sub ver].[sub index]",
983 * ex: V0.16.1.0
984 *
985 */
rtw_hal_mac_get_version(char * ver_str,u16 len)986 void rtw_hal_mac_get_version(char *ver_str, u16 len)
987 {
988 _os_snprintf(ver_str, len, "V%u.%u.%u.%u",
989 MAC_AX_MAJOR_VER, MAC_AX_PROTOTYPE_VER,
990 MAC_AX_SUB_VER, MAC_AX_SUB_INDEX);
991 }
992
993 /**
994 * rtw_hal_mac_get_fw_ver() - Get Firmware version
995 * @hal_info: struct hal_info_t *
996 * @ver_str: string buffer for storing version string
997 * @len: string buffer length
998 *
999 * Firmware version format is "V[major].[ver].[sub ver].[sub index]",
1000 * ex: V0.5.0
1001 *
1002 */
rtw_hal_mac_get_fw_ver(struct hal_info_t * hal_info,char * ver_str,u16 len)1003 void rtw_hal_mac_get_fw_ver(struct hal_info_t *hal_info, char *ver_str, u16 len)
1004 {
1005 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1006
1007 _os_snprintf(ver_str, len, "V%u.%u.%u.%u",
1008 mac->fw_info.major_ver,mac->fw_info.minor_ver,
1009 mac->fw_info.sub_ver, mac->fw_info.sub_idx);
1010 }
1011
1012 #define _IS_FW_READY(hal_info) \
1013 (hal_to_mac(hal_info)->sm.fwdl == MAC_AX_FWDL_INIT_RDY)
1014
hal_mac_print_fw_version(struct hal_info_t * hal_info)1015 void hal_mac_print_fw_version(struct hal_info_t *hal_info)
1016 {
1017 char ver[20] = {0};
1018 rtw_hal_mac_get_fw_ver(hal_info, ver, 20);
1019 PHL_PRINT("%s: FW version %s, %sReady\n", __func__, ver,
1020 _IS_FW_READY(hal_info) ? "" : "Not ");
1021 }
1022
rtw_hal_mac_init(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info)1023 u32 rtw_hal_mac_init(struct rtw_phl_com_t *phl_com,
1024 struct hal_info_t *hal_info)
1025 {
1026 struct rtw_hal_com_t *hal_com = hal_info->hal_com;
1027 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
1028 struct mac_ax_adapter *mac = NULL;
1029 struct mac_ax_ops *mac_ops;
1030 u32 status;
1031
1032 #ifdef DBG_HAL_MAC_MEM_MOINTOR
1033 _os_atomic_set(hal_com->drv_priv, &(hal_com->hal_mac_mem), 0);
1034 #endif
1035 hal_info->mac = NULL;
1036 #ifdef CONFIG_NEW_HALMAC_INTERFACE
1037 status = new_mac_ax_ops_init(phl_com, hal_com, &mac, &mac_ops);
1038 #else
1039 {
1040 enum mac_ax_intf intf = MAC_AX_INTF_INVALID;
1041 if (phl_com->hci_type == RTW_HCI_PCIE)
1042 intf = MAC_AX_INTF_PCIE;
1043 else if (phl_com->hci_type == RTW_HCI_USB)
1044 intf = MAC_AX_INTF_USB;
1045 else if ((phl_com->hci_type == RTW_HCI_SDIO) ||
1046 (phl_com->hci_type == RTW_HCI_GSPI))
1047 intf = MAC_AX_INTF_SDIO;
1048
1049 rtw_plt_cb_init();
1050 status = mac_ax_ops_init(hal_com,
1051 &rtw_plt_cb, intf, &mac, &mac_ops);
1052 #if MAC_AX_PHL_H2C
1053 if (status == MACSUCCESS && mac != NULL)
1054 mac_ax_phl_init(phl_com, mac);
1055 #endif
1056 }
1057 #endif
1058
1059 if (status != MACSUCCESS) {
1060 PHL_ERR("%s: halmac_init_adapter fail!(status=%d-%s)\n",
1061 __func__, status, mac_sstr(status));
1062 hal_status = RTW_HAL_STATUS_MAC_INIT_FAILURE;
1063 goto error_mac_init;
1064 }
1065
1066 if (!mac) {
1067 PHL_ERR("halmac alloc failed\n");
1068 hal_status = RTW_HAL_STATUS_MAC_INIT_FAILURE;
1069 /*_os_warn_on(1);*/
1070 goto error_mac_init;
1071 }
1072 hal_com->cv = mac->hw_info->cv;
1073 hal_info->mac = mac;
1074
1075 return hal_status;
1076
1077 error_mac_init:
1078 if (mac) {
1079 mac_ax_ops_exit(mac);
1080 hal_info->mac = NULL;
1081 }
1082 return hal_status;
1083 }
1084
rtw_hal_mac_deinit(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info)1085 u32 rtw_hal_mac_deinit(struct rtw_phl_com_t *phl_com,
1086 struct hal_info_t *hal_info)
1087 {
1088 #ifdef DBG_HAL_MAC_MEM_MOINTOR
1089 struct rtw_hal_com_t *hal = hal_info->hal_com;
1090 #endif
1091 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1092 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
1093
1094 if (mac) {
1095 if(mac_ax_ops_exit(mac) == MACSUCCESS) {
1096 hal_status = RTW_HAL_STATUS_FAILURE;
1097
1098 hal_info->mac = NULL;
1099 } else {
1100 PHL_ERR("%s failed\n", __func__);
1101 }
1102 }
1103 #ifdef DBG_HAL_MAC_MEM_MOINTOR
1104 PHL_INFO("[PHL-MEM] %s HALMAC memory :%d\n", __func__,
1105 _os_atomic_read(hal_to_drvpriv(hal_info), &(hal->hal_mac_mem)));
1106 #endif
1107
1108 return hal_status;
1109 }
1110
1111
1112 #ifdef CONFIG_SDIO_HCI
rtw_hal_mac_sdio_cfg(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info,struct rtw_ic_info * ic_info)1113 void rtw_hal_mac_sdio_cfg(struct rtw_phl_com_t *phl_com,
1114 struct hal_info_t *hal_info,
1115 struct rtw_ic_info *ic_info)
1116 {
1117 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
1118 struct mac_ax_sdio_info info;
1119
1120 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
1121
1122 info.sdio_4byte = (ic_info->sdio_info.io_align_sz == 4)
1123 ? MAC_AX_SDIO_4BYTE_MODE_RW : MAC_AX_SDIO_4BYTE_MODE_DISABLE;
1124
1125 if (ic_info->sdio_info.sd3_bus_mode)
1126 info.spec_ver = MAC_AX_SDIO_SPEC_VER_3_00;
1127 else
1128 info.spec_ver = MAC_AX_SDIO_SPEC_VER_2_00;
1129
1130 info.block_size = ic_info->sdio_info.block_sz;
1131
1132 if (ic_info->sdio_info.tx_512_by_byte_mode)
1133 info.opn_mode = MAC_AX_SDIO_OPN_MODE_BYTE;
1134 else
1135 info.opn_mode = MAC_AX_SDIO_OPN_MODE_BLOCK;
1136
1137 /*
1138 * MAC_AX_HW_SDIO_INFO always return MACSUCCESS,
1139 * so don't check return value here.
1140 */
1141 mac->ops->set_hw_value(mac, MAC_AX_HW_SDIO_INFO, &info);
1142 }
1143
1144 /**
1145 * rtw_hal_mac_sdio_tx_cfg - SDIO TX related setting
1146 * @hal: pointer of struct rtw_hal_com_t
1147 *
1148 * Configure setting for SDIO TX.
1149 * All tx related setting which need to be config after mac init(power on)
1150 * should be included here.
1151 *
1152 * Config tx mode to DUMMY_AUTO to release (32K-4) bytes TX size limitation,
1153 * but this mode only work on SDIO host supporting block mode.
1154 *
1155 * No return value for this function.
1156 */
rtw_hal_mac_sdio_tx_cfg(struct rtw_hal_com_t * hal)1157 void rtw_hal_mac_sdio_tx_cfg(struct rtw_hal_com_t *hal)
1158 {
1159 struct hal_info_t *hal_info = hal->hal_priv;
1160 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1161 enum mac_ax_sdio_tx_mode mode = MAC_AX_SDIO_TX_MODE_DUMMY_AUTO;
1162 u32 err;
1163
1164
1165 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SDIO_TX_MODE, &mode);
1166 if (err != MACSUCCESS)
1167 PHL_ERR("%s: set TX mode(%u) FAIL!(%u)\n", __func__, mode, err);
1168 }
1169
1170 /**
1171 * rtw_hal_mac_sdio_rx_agg_cfg - SDIO RX aggregation setting
1172 * @hal: pointer of struct rtw_hal_com_t
1173 * @enable: enable function or not
1174 * @drv_define: use driver's parameters or not
1175 * @timeout: timeout threshold, unit 1us
1176 * @size: size threshold, unit 1KB
1177 * @pkt_num: packet number threshold
1178 *
1179 * Configure setting for SDIO RX aggregation.
1180 *
1181 * No return value for this function.
1182 */
rtw_hal_mac_sdio_rx_agg_cfg(struct rtw_hal_com_t * hal,bool enable,u8 drv_define,u8 timeout,u8 size,u8 pkt_num)1183 void rtw_hal_mac_sdio_rx_agg_cfg(struct rtw_hal_com_t *hal, bool enable,
1184 u8 drv_define, u8 timeout, u8 size, u8 pkt_num)
1185 {
1186 struct hal_info_t *hal_info = hal->hal_priv;
1187 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1188 struct mac_ax_rx_agg_cfg cfg = {MAC_AX_RX_AGG_MODE_NONE};
1189
1190
1191 if (enable) {
1192 cfg.mode = MAC_AX_RX_AGG_MODE_DMA;
1193 cfg.thold.drv_define = drv_define;
1194 cfg.thold.timeout = timeout;
1195 cfg.thold.size = size;
1196 cfg.thold.pkt_num = pkt_num;
1197 }
1198
1199 mac->ops->set_hw_value(mac, MAC_AX_HW_SDIO_RX_AGG, &cfg);
1200 }
1201
1202 /* AX TX DESC */
1203 /* DWORD 0 ; Offset 00h */
1204 #define GET_TX_AX_DESC_CHANNEL_DMA(_wd) LE_BITS_TO_4BYTE(_wd, 16, 4)
1205 #define GET_TX_AX_DESC_WP_OFFSET(_wd) LE_BITS_TO_4BYTE(_wd, 24, 8)
1206
1207 /* DWORD 2 ; Offset 08h */
1208 #define GET_TX_AX_DESC_PKT_LEN(_wd) LE_BITS_TO_2BYTE(_wd+8, 0, 14)
1209
1210 /**
1211 * rtw_hal_mac_sdio_check_tx_allow - Check hardware resource enough to xmit
1212 * @hal: pointer of struct rtw_hal_com_t
1213 * @dma_ch: dma channel to xmit, should be the same as field "CHANNEL_DMA "in WD
1214 * @buf: data buffer to xmit
1215 * @len: data buffer length
1216 * @agg_count: how many packets aggregated in this buffer
1217 * @pkt_len: array to store each packet's lenght in this buffer,
1218 * pkt_len should be the same as field "PKT_LEN" in WD
1219 * @wp_offset: array to store each packet's wp_offset in this buffer
1220 * wp_offset should be the same as field "WP_OFFSET" in WD
1221 * @txaddr: return SDIO TX address for this tx buffer, and only valid when
1222 * function's return value is true.
1223 * @txlen: return SDIO TX length for this tx buffer, and only valid when
1224 * function's return value is true. txlen would >= len and align
1225 * to particular size by IC.
1226 *
1227 * Check if hardware resource is enough to send this tx buffer and return
1228 * SDIO TX address.
1229 *
1230 * Return true if hardware resource is enough, otherwise false.
1231 */
rtw_hal_mac_sdio_check_tx_allow(struct rtw_hal_com_t * hal,u8 dma_ch,u8 * buf,u32 len,u8 agg_count,u16 * pkt_len,u8 * wp_offset,u32 * txaddr,u32 * txlen)1232 bool rtw_hal_mac_sdio_check_tx_allow(struct rtw_hal_com_t *hal, u8 dma_ch,
1233 u8 *buf, u32 len, u8 agg_count,
1234 u16 *pkt_len, u8 *wp_offset, u32 *txaddr,
1235 u32 *txlen)
1236 {
1237 struct hal_info_t *hal_info = hal->hal_priv;
1238 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1239 struct mac_ax_sdio_tx_info info = {0};
1240 int i;
1241 u32 err;
1242 u16 pkt_len_tmp;
1243 u8 wp_offset_tmp;
1244 u8 wd_ch;
1245
1246
1247 /* For H2C, pkt_len & wp_offset may be invalid */
1248 if (!pkt_len && (agg_count == 1)) {
1249 pkt_len_tmp = GET_TX_AX_DESC_PKT_LEN(buf);
1250 pkt_len = &pkt_len_tmp;
1251 }
1252 if (!wp_offset && (agg_count == 1)) {
1253 wp_offset_tmp = (u8)GET_TX_AX_DESC_WP_OFFSET(buf);
1254 wp_offset = &wp_offset_tmp;
1255 }
1256
1257 /* check tx wd */
1258 wd_ch = (u8)GET_TX_AX_DESC_CHANNEL_DMA(buf);
1259 if (wd_ch != dma_ch) {
1260 PHL_ERR("%s: tx channel abnormal, %u(wd) != %u(input)\n",
1261 __func__, wd_ch, dma_ch);
1262 debug_dump_data(buf, len&0xFFFF0000?0xFFFF:(u16)len, "wd:");
1263 }
1264
1265 info.total_size = len;
1266 info.dma_txagg_num = agg_count;
1267 info.ch_dma = dma_ch;
1268 /* halmac request pkt_size should be little endian */
1269 for (i = 0; i < agg_count; i++)
1270 pkt_len[i] = cpu_to_le16(pkt_len[i]);
1271 info.pkt_size = (u8*)pkt_len;
1272 info.wp_offset = wp_offset;
1273 info.chk_cnt = 5;
1274
1275 err = mac->ops->intf_ops->tx_allow_sdio(mac, &info);
1276 if (err != MACSUCCESS) {
1277 PHL_DBG("%s: tx allow fail! (%d)\n", __func__, err);
1278 goto err_exit;
1279 }
1280
1281 err = mac->ops->intf_ops->tx_cmd_addr_sdio(mac, &info, txaddr);
1282 if (err != MACSUCCESS) {
1283 PHL_ERR("%s: get tx addr fail! (%d)\n", __func__, err);
1284 goto err_exit;
1285 }
1286
1287 /*
1288 * TX I/O size should align to 8 bytes on SDIO byte count mode,
1289 * or hardware would go wrong.
1290 *
1291 * TODO: alignment size would be get from HALMAC return.
1292 */
1293 *txlen = _ALIGN(len, 8);
1294
1295 return true;
1296
1297 err_exit:
1298 /* Revert pkt_len to CPU endian */
1299 for (i = 0; i < agg_count; i++)
1300 pkt_len[i] = le16_to_cpu(pkt_len[i]);
1301
1302 return false;
1303 }
1304
_pkt_type_mac2phl(enum mac_ax_pkt_t mac_type)1305 static enum rtw_rx_type _pkt_type_mac2phl(enum mac_ax_pkt_t mac_type)
1306 {
1307 enum rtw_rx_type t = RTW_RX_TYPE_MAX;
1308
1309
1310 switch (mac_type) {
1311 case MAC_AX_PKT_DATA:
1312 t = RTW_RX_TYPE_WIFI;
1313 break;
1314 case MAC_AX_PKT_MGNT:
1315 case MAC_AX_PKT_CTRL:
1316 case MAC_AX_PKT_8023:
1317 case MAC_AX_PKT_H2C:
1318 case MAC_AX_PKT_FWDL:
1319 /* TODO: unknown */
1320 PHL_WARN("%s: unhandled RX type(%d)\n", __func__, mac_type);
1321 break;
1322 case MAC_AX_PKT_C2H:
1323 t = RTW_RX_TYPE_C2H;
1324 break;
1325 case MAC_AX_PKT_PPDU:
1326 t = RTW_RX_TYPE_PPDU_STATUS;
1327 break;
1328 case MAC_AX_PKT_CH_INFO:
1329 t = RTW_RX_TYPE_CHANNEL_INFO;
1330 break;
1331 case MAC_AX_PKT_DFS:
1332 t = RTW_RX_TYPE_DFS_RPT;
1333 break;
1334 default:
1335 PHL_WARN("%s: unknon RX type(%d)\n", __func__, mac_type);
1336 break;
1337 }
1338
1339 return t;
1340 }
1341
hal_mac_parse_rxpkt_info(struct mac_ax_rxpkt_info * info,struct rtw_r_meta_data * meta)1342 static void hal_mac_parse_rxpkt_info(struct mac_ax_rxpkt_info *info,
1343 struct rtw_r_meta_data *meta)
1344 {
1345 meta->pktlen = (u16)info->pktsize; /* DW0 [0:13] */
1346 meta->shift = info->shift; /* DW0 [14:15] */
1347 meta->rpkt_type = _pkt_type_mac2phl(info->type); /* DW0 [24:27] */
1348 meta->drv_info_size = info->drvsize; /* DW0 [28:30] */
1349 meta->long_rxd = (info->rxdlen == RXD_LONG_LEN) ? 1 : 0; /* DW0 [31:31] */
1350
1351 if (info->type == MAC_AX_PKT_DATA) {
1352 #if 0
1353 meta->dma_ch;
1354 meta->hal_port;
1355 meta->ta[6]; /* Transmitter Address */
1356 #endif
1357 #if 0
1358 meta->wl_hd_iv_len; /* DW0 [16:21] */
1359 meta->bb_sel; /* DW0 [22:22] */
1360 meta->mac_info_vld; /* DW0 [23:23] */
1361 #endif
1362 #if 0
1363 meta->long_rxd; /* DW0 [31:31] */
1364
1365 meta->ppdu_type; /* DW1 [0:3] */
1366 meta->ppdu_cnt; /* DW1 [4:6] */
1367 meta->sr_en; /* DW1 [7:7] */
1368 meta->user_id; /* DW1 [8:15] */
1369 meta->rx_rate; /* DW1 [16:24] */
1370 meta->rx_gi_ltf; /* DW1 [25:27] */
1371 meta->non_srg_ppdu; /* DW1 [28:28] */
1372 meta->inter_ppdu; /* DW1 [29:29] */
1373 meta->bw; /* DW1 [30:31] */
1374
1375 meta->freerun_cnt; /* DW2 [0:31] */
1376
1377 meta->a1_match; /* DW3 [0:0] */
1378 meta->sw_dec; /* DW3 [1:1] */
1379 meta->hw_dec; /* DW3 [2:2] */
1380 meta->ampdu; /* DW3 [3:3] */
1381 meta->ampdu_end_pkt; /* DW3 [4:4] */
1382 meta->amsdu; /* DW3 [5:5] */
1383 meta->amsdu_cut; /* DW3 [6:6] */
1384 meta->last_msdu; /* DW3 [7:7] */
1385 meta->bypass; /* DW3 [8:8] */
1386 #endif
1387 meta->crc32 = info->u.data.crc_err; /* DW3 [9:9] */
1388 meta->icverr = info->u.data.icv_err; /* DW3 [10:10] */
1389 #if 0
1390 meta->magic_wake; /* DW3 [11:11] */
1391 meta->unicast_wake; /* DW3 [12:12] */
1392 meta->pattern_wake; /* DW3 [13:13] */
1393 meta->get_ch_info; /* DW3 [14:15] */
1394 meta->pattern_idx; /* DW3 [16:20] */
1395 meta->target_idc; /* DW3 [21:23] */
1396 meta->chksum_ofld_en; /* DW3 [24:24] */
1397 meta->with_llc; /* DW3 [25:25] */
1398 meta->rx_statistics; /* DW3 [26:26] */
1399
1400 meta->frame_type; /* DW4 [0:1] */
1401 meta->mc; /* DW4 [2:2] */
1402 meta->bc; /* DW4 [3:3] */
1403 meta->more_data; /* DW4 [4:4] */
1404 meta->more_frag; /* DW4 [5:5] */
1405 meta->pwr_bit; /* DW4 [6:6] */
1406 meta->qos; /* DW4 [7:7] */
1407 meta->tid; /* DW4 [8:11] */
1408 meta->eosp; /* DW4 [12:12] */
1409 meta->htc; /* DW4 [13:13] */
1410 meta->q_null; /* DW4 [14:14] */
1411 meta->seq; /* DW4 [16:27] */
1412 meta->frag_num; /* DW4 [28:31] */
1413
1414 meta->sec_cam_idx; /* DW5 [0:7] */
1415 meta->addr_cam; /* DW5 [8:15] */
1416 meta->macid; /* DW5 [16:23] */
1417 meta->rx_pl_id; /* DW5 [24:27] */
1418 meta->addr_cam_vld; /* DW5 [28:28] */
1419 meta->addr_fwd_en; /* DW5 [29:29] */
1420 meta->rx_pl_match; /* DW5 [30:30] */
1421
1422 meta->mac_addr[6]; /* DW6 [0:31] DW7 [0:15] */
1423 meta->smart_ant; /* DW7 [16:16] */
1424 meta->sec_type; /* DW7 [17:20] */
1425 #endif
1426 } else if (info->type == MAC_AX_PKT_PPDU) {
1427 meta->mac_info_vld = info->u.ppdu.mac_info; /* DW0 [23:23] */
1428 }
1429 }
1430
1431 /* AX RX DESC */
1432 /* DWORD 0 ; Offset 00h */
1433 #define GET_RX_AX_DESC_PKT_LEN(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 0, 14)
1434 #define GET_RX_AX_DESC_SHIFT(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 14, 2)
1435 #define GET_RX_AX_DESC_HDR_IV_L(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 16, 6)
1436 #define GET_RX_AX_DESC_BB_SEL(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 22, 1)
1437 #define GET_RX_AX_DESC_MAC_INFO_VLD(__pRxStatusDesc) LE_BITS_TO_4BYTE( __pRxStatusDesc, 23, 1)
1438 #define GET_RX_AX_DESC_RPKT_TYPE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 24, 4)
1439 #define GET_RX_AX_DESC_DRV_INFO_SIZE(__pRxStatusDesc) LE_BITS_TO_4BYTE( __pRxStatusDesc, 28, 3)
1440 #define GET_RX_AX_DESC_LONG_RXD(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc, 31, 1)
1441
1442 /* DWORD 1 ; Offset 04h */
1443 #define GET_RX_AX_DESC_PPDU_TYPE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 0, 4)
1444 #define GET_RX_AX_DESC_PPDU_CNT(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 4, 3)
1445 #define GET_RX_AX_DESC_SR_EN(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 7, 1)
1446 #define GET_RX_AX_DESC_USER_ID(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 8, 8)
1447 #define GET_RX_AX_DESC_RX_DATARATE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 16, 9)
1448 #define GET_RX_AX_DESC_RX_GI_LTF(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 25, 3)
1449 #define GET_RX_AX_DESC_NON_SRG_PPDU(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 28, 1)
1450 #define GET_RX_AX_DESC_INTER_PPDU(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 29, 1)
1451 #define GET_RX_AX_DESC_BW(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+4, 30, 2)
1452
1453 /* DWORD 2 ; Offset 08h */
1454 #define GET_RX_AX_DESC_FREERUN_CNT(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+8, 0, 32)
1455
1456 /* DWORD 3 ; Offset 0ch */
1457 #define GET_RX_AX_DESC_A1_MATCH(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 0, 1)
1458 #define GET_RX_AX_DESC_SW_DEC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 1, 1)
1459 #define GET_RX_AX_DESC_HW_DEC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 2, 1)
1460 #define GET_RX_AX_DESC_AMPDU(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 3, 1)
1461 #define GET_RX_AX_DESC_AMPDU_EDN_PKT(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 4, 1)
1462 #define GET_RX_AX_DESC_AMSDU(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 5, 1)
1463 #define GET_RX_AX_DESC_AMSDU_CUT(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 6, 1)
1464 #define GET_RX_AX_DESC_LAST_MSDU(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 7, 1)
1465 #define GET_RX_AX_DESC_BYPASS(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 8, 1)
1466 #define GET_RX_AX_DESC_CRC32(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 9, 1)
1467 #define GET_RX_AX_DESC_ICVERR(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 10, 1)
1468 #define GET_RX_AX_DESC_MAGIC_WAKE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 11, 1)
1469 #define GET_RX_AX_DESC_UNICAST_WAKE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 12, 1)
1470 #define GET_RX_AX_DESC_PATTERN_WAKE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 13, 1)
1471
1472 #define GET_RX_AX_DESC_CH_INFO(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 14, 1)
1473 #define GET_RX_AX_DESC_STATISTICS(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 15, 1)
1474 #define GET_RX_AX_DESC_PATTERN_IDX(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 16, 5)
1475 #define GET_RX_AX_DESC_TARGET_IDC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 21, 3)
1476 #define GET_RX_AX_DESC_CHKSUM_OFFLOAD(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 24, 1)
1477 #define GET_RX_AX_DESC_WITH_LLC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+12, 25, 1)
1478
1479 /* DWORD 4 ; Offset 10h */
1480 #define GET_RX_AX_DESC_TYPE(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 0, 2)
1481 #define GET_RX_AX_DESC_MC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 2, 1)
1482 #define GET_RX_AX_DESC_BC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 3, 1)
1483 #define GET_RX_AX_DESC_MD(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 4, 1)
1484 #define GET_RX_AX_DESC_MF(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 5, 1)
1485 #define GET_RX_AX_DESC_PWR(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 6, 1)
1486 #define GET_RX_AX_DESC_QOS(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 7, 1)
1487 #define GET_RX_AX_DESC_TID(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 8, 4)
1488 #define GET_RX_AX_DESC_EOSP(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 12, 1)
1489 #define GET_RX_AX_DESC_HTC(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 13, 1)
1490 #define GET_RX_AX_DESC_QNULL(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 14, 1)
1491
1492 #define GET_RX_AX_DESC_SEQ(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 16, 12)
1493 #define GET_RX_AX_DESC_FRAG(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+16, 28, 4)
1494
1495 /* DWORD 5 ; Offset 14h */
1496 #define GET_RX_AX_DESC_CAM_IDX(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 0, 8)
1497 #define GET_RX_AX_DESC_ADDR_CAM(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 8, 8)
1498 #define GET_RX_AX_DESC_MACID(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 16, 8)
1499 #define GET_RX_AX_DESC_PL_ID(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 24, 4)
1500 #define GET_RX_AX_DESC_CAM_VLD(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 28, 1)
1501 #define GET_RX_AX_DESC_FWD_EN(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 29, 1)
1502 #define GET_RX_AX_DESC_PL_MATCH(__pRxStatusDesc) LE_BITS_TO_4BYTE(__pRxStatusDesc+20, 30, 1)
1503
1504 #ifdef CONFIG_PHL_CSUM_OFFLOAD_RX
hal_mac_parse_rxd_checksume(struct rtw_hal_com_t * hal,struct rtw_r_meta_data * meta,u8 status)1505 static void hal_mac_parse_rxd_checksume(struct rtw_hal_com_t *hal,
1506 struct rtw_r_meta_data *meta, u8 status)
1507 {
1508 if ((status == MAC_AX_CHKSUM_OFD_IPV4_TCP_OK) ||
1509 (status == MAC_AX_CHKSUM_OFD_IPV6_TCP_OK) ||
1510 (status == MAC_AX_CHKSUM_OFD_IPV4_UDP_OK) ||
1511 (status == MAC_AX_CHKSUM_OFD_IPV6_UDP_OK))
1512 meta->chksum_status = 0;
1513 else
1514 meta->chksum_status = 1;
1515 }
1516 #endif
1517
hal_mac_parse_rxd(struct rtw_hal_com_t * hal,u8 * rxd,struct rtw_r_meta_data * meta)1518 static void hal_mac_parse_rxd(struct rtw_hal_com_t *hal,
1519 u8 *rxd, struct rtw_r_meta_data *meta)
1520 {
1521 #if 0
1522 meta->pktlen = GET_RX_AX_DESC_PKT_LEN(rxd);
1523 meta->shift = GET_RX_AX_DESC_SHIFT(rxd);
1524 meta->wl_hd_iv_len = GET_RX_AX_DESC_HDR_IV_L(rxd);
1525 meta->bb_sel = GET_RX_AX_DESC_BB_SEL(rxd);
1526 meta->mac_info_vld = GET_RX_AX_DESC_MAC_INFO_VLD(rxd);
1527 meta->rpkt_type = GET_RX_AX_DESC_RPKT_TYPE(rxd);
1528 meta->drv_info_size = GET_RX_AX_DESC_DRV_INFO_SIZE(rxd);
1529 meta->long_rxd = GET_RX_AX_DESC_LONG_RXD(rxd);
1530
1531 meta->ppdu_type = GET_RX_AX_DESC_PPDU_TYPE(rxd);
1532 meta->ppdu_cnt = GET_RX_AX_DESC_PPDU_CNT(rxd);
1533 meta->sr_en = GET_RX_AX_DESC_SR_EN(rxd);
1534 meta->user_id = GET_RX_AX_DESC_USER_ID(rxd);
1535 meta->rx_rate = GET_RX_AX_DESC_RX_DATARATE(rxd);
1536 meta->rx_gi_ltf = GET_RX_AX_DESC_RX_GI_LTF(rxd);
1537 meta->non_srg_ppdu = GET_RX_AX_DESC_NON_SRG_PPDU(rxd);
1538 meta->inter_ppdu = GET_RX_AX_DESC_INTER_PPDU(rxd);
1539 meta->bw = GET_RX_AX_DESC_BW(rxd);
1540
1541 meta->freerun_cnt = GET_RX_AX_DESC_FREERUN_CNT(rxd);
1542
1543 meta->a1_match = GET_RX_AX_DESC_A1_MATCH(rxd);
1544 #endif
1545 meta->sw_dec = GET_RX_AX_DESC_SW_DEC(rxd);
1546 meta->hw_dec = GET_RX_AX_DESC_HW_DEC(rxd);
1547 #if 0
1548 meta->ampdu = GET_RX_AX_DESC_AMPDU(rxd);
1549 meta->ampdu_end_pkt = GET_RX_AX_DESC_AMPDU_EDN_PKT(rxd);
1550 meta->amsdu = GET_RX_AX_DESC_AMSDU(rxd);
1551 #endif
1552 meta->amsdu_cut = GET_RX_AX_DESC_AMSDU_CUT(rxd);
1553 meta->last_msdu = GET_RX_AX_DESC_LAST_MSDU(rxd);
1554 #if 0
1555 meta->bypass = GET_RX_AX_DESC_BYPASS(rxd);
1556 meta->crc32 = GET_RX_AX_DESC_CRC32(rxd);
1557 meta->icverr = GET_RX_AX_DESC_ICVERR(rxd);
1558 meta->magic_wake = GET_RX_AX_DESC_MAGIC_WAKE(rxd);
1559 meta->unicast_wake = GET_RX_AX_DESC_UNICAST_WAKE(rxd);
1560 meta->pattern_wake = GET_RX_AX_DESC_PATTERN_WAKE(rxd);
1561 meta->get_ch_info = GET_RX_AX_DESC_CH_INFO(rxd);
1562 meta->rx_statistics = GET_RX_AX_DESC_STATISTICS(rxd);
1563
1564 meta->pattern_idx = GET_RX_AX_DESC_PATTERN_IDX(rxd);
1565 meta->target_idc = GET_RX_AX_DESC_TARGET_IDC(rxd);
1566 meta->chksum_ofld_en = GET_RX_AX_DESC_CHKSUM_OFFLOAD(rxd);
1567 meta->with_llc = GET_RX_AX_DESC_WITH_LLC(rxd);
1568 #endif
1569 meta->chksum_ofld_en = GET_RX_AX_DESC_CHKSUM_OFFLOAD(rxd);
1570
1571 if (meta->long_rxd == 1) {
1572 #if 0
1573 meta->frame_type = GET_RX_AX_DESC_TYPE(rxd);
1574 #endif
1575 meta->mc = GET_RX_AX_DESC_MC(rxd);
1576 meta->bc = GET_RX_AX_DESC_BC(rxd);
1577 #if 0
1578 meta->more_data = GET_RX_AX_DESC_MD(rxd);
1579 #endif
1580 meta->more_frag = GET_RX_AX_DESC_MF(rxd);
1581 #if 0
1582 meta->pwr_bit = GET_RX_AX_DESC_PWR(rxd);
1583 #endif
1584 meta->qos = GET_RX_AX_DESC_QOS(rxd);
1585
1586 meta->tid = GET_RX_AX_DESC_TID(rxd);
1587 #if 0
1588 meta->eosp = GET_RX_AX_DESC_EOSP(rxd);
1589 meta->htc = GET_RX_AX_DESC_HTC(rxd);
1590 #endif
1591 meta->q_null = GET_RX_AX_DESC_QNULL(rxd);
1592 meta->seq = GET_RX_AX_DESC_SEQ(rxd);
1593 meta->frag_num = GET_RX_AX_DESC_FRAG(rxd);
1594
1595 #if 0
1596 meta->sec_cam_idx = GET_RX_AX_DESC_CAM_IDX(rxd);
1597 meta->addr_cam = GET_RX_AX_DESC_ADDR_CAM(rxd);
1598
1599 meta->macid = GET_RX_AX_DESC_MACID(rxd);
1600 meta->rx_pl_id = GET_RX_AX_DESC_PL_ID(rxd);
1601 meta->addr_cam_vld = GET_RX_AX_DESC_CAM_VLD(rxd);
1602 meta->addr_fwd_en = GET_RX_AX_DESC_FWD_EN(rxd);
1603 meta->rx_pl_match = GET_RX_AX_DESC_PL_MATCH(rxd);
1604 #endif
1605
1606 _os_mem_cpy(hal->drv_priv,
1607 (void*)&meta->mac_addr, (void*)(rxd + 24), MAC_ALEN);
1608 }
1609 }
1610
rtw_hal_mac_sdio_parse_rx(struct rtw_hal_com_t * hal,struct rtw_rx_buf * rxbuf)1611 int rtw_hal_mac_sdio_parse_rx(struct rtw_hal_com_t *hal,
1612 struct rtw_rx_buf *rxbuf)
1613 {
1614 struct hal_info_t *hal_info = hal->hal_priv;
1615 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1616 struct mac_ax_rxpkt_info info;
1617 struct sdio_rx_pkt *pkt;
1618 u8 *ptr;
1619 u32 len;
1620 int i;
1621 u32 offset;
1622 u32 err = MACSUCCESS;
1623
1624
1625 rxbuf->agg_cnt = 0;
1626 rxbuf->agg_start = 0;
1627 ptr = rxbuf->ptr;
1628 len = rxbuf->len;
1629
1630 for (i = 0; i < MAX_BUS_RX_AGG; i++) {
1631 _os_mem_set(hal->drv_priv, &info, 0, sizeof(info));
1632 err = mac->ops->parse_rxdesc(mac, &info, ptr, len);
1633 if (err != MACSUCCESS) {
1634 PHL_ERR("%s: agg_idx=%d, len=%u(%u), parse_rxdesc FAIL!(%u)\n",
1635 __func__, i, len, rxbuf->len, err);
1636 rxbuf->len -= len;
1637 len = 0;
1638 break;
1639 }
1640
1641 pkt = &rxbuf->pkt[i];
1642 _os_mem_set(hal->drv_priv, pkt, 0, sizeof(*pkt));
1643
1644 pkt->wd = ptr;
1645 pkt->wd_len = (u8)info.rxdlen;
1646 offset = info.rxdlen + (info.drvsize * 8) + (info.shift * 2);
1647 pkt->pkt = ptr + offset;
1648 pkt->pkt_len = (u16)info.pktsize;
1649 hal_mac_parse_rxpkt_info(&info, &pkt->meta);
1650 hal_mac_parse_rxd(hal, ptr, &pkt->meta);
1651 _os_mem_cpy(hal->drv_priv, pkt->meta.ta, pkt->pkt + 10, 6);
1652
1653 offset += info.pktsize;
1654
1655 offset = _ALIGN(offset, 8);
1656 #ifdef CONFIG_PHL_CSUM_OFFLOAD_RX
1657 if (pkt->meta.chksum_ofld_en) {
1658 u8 status;
1659 u32 result;
1660
1661 status = *(ptr + offset);
1662 result = mac->ops->chk_rx_tcpip_chksum_ofd(mac, status);
1663 hal_mac_parse_rxd_checksume(hal, &pkt->meta, result);
1664 offset += 8;
1665 }
1666 #endif /* CONFIG_PHL_CSUM_OFFLOAD_RX */
1667 ptr += offset;
1668 if (offset >= len) {
1669 len = 0;
1670 i++;
1671 break;
1672 }
1673 len -= offset;
1674 }
1675
1676 rxbuf->agg_cnt = (u8)i;
1677 if (len) {
1678 /* not finish yet */
1679 rxbuf->next_ptr = ptr;
1680 offset = (u32)(ptr - rxbuf->ptr);
1681 } else {
1682 rxbuf->next_ptr = NULL;
1683 offset = rxbuf->len;
1684 }
1685
1686 return offset;
1687 }
1688
rtw_hal_mac_sdio_rx(struct rtw_hal_com_t * hal,struct rtw_rx_buf * rxbuf)1689 int rtw_hal_mac_sdio_rx(struct rtw_hal_com_t *hal, struct rtw_rx_buf *rxbuf)
1690 {
1691 u32 len;
1692
1693
1694 len = hal_read32(hal, R_AX_SDIO_RX_REQ_LEN) & B_AX_RX_REQ_LEN_MSK;
1695 if (!len)
1696 return 0;
1697 if (len > rxbuf->buf_len) {
1698 /* TODO: read and drop */
1699 return 0;
1700 }
1701
1702 if (_FAIL == hal_sdio_cmd53_r(hal, SDIO_CMD_ADDR_RXFF, len, rxbuf->buffer))
1703 return 0;
1704
1705 rxbuf->used_len = len;
1706 rxbuf->ptr = rxbuf->buffer;
1707 rxbuf->len = len;
1708
1709 #ifndef CONFIG_PHL_SDIO_READ_RXFF_IN_INT
1710 len = rtw_hal_mac_sdio_parse_rx(hal, rxbuf);
1711 #endif
1712
1713 return len;
1714 }
1715 #endif /*CONFIG_SDIO_HCI*/
1716
rtw_hal_mac_get_pwr_state(struct hal_info_t * hal_info,enum rtw_mac_pwr_st * pwr_state)1717 enum rtw_hal_status rtw_hal_mac_get_pwr_state(struct hal_info_t *hal_info,
1718 enum rtw_mac_pwr_st *pwr_state)
1719 {
1720 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1721 struct mac_ax_ops *hal_mac_ops = mac->ops;
1722 enum mac_ax_mac_pwr_st st;
1723
1724 if (hal_mac_ops->get_hw_value(mac, MAC_AX_HW_GET_PWR_STATE, &st) != MACSUCCESS)
1725 return RTW_HAL_STATUS_FAILURE;
1726
1727 PHL_INFO("%s : retrieve WL MAC state %u\n", __func__, st);
1728
1729 switch (st) {
1730 case MAC_AX_MAC_OFF:
1731 *pwr_state = RTW_MAC_PWR_OFF;
1732 break;
1733 case MAC_AX_MAC_ON:
1734 *pwr_state = RTW_MAC_PWR_ON;
1735 break;
1736 case MAC_AX_MAC_LPS:
1737 *pwr_state = RTW_MAC_PWR_LPS;
1738 break;
1739 default:
1740 *pwr_state = RTW_MAC_PWR_NONE;
1741 break;
1742 }
1743
1744 return RTW_HAL_STATUS_SUCCESS;
1745 }
1746
1747 /* halmac wrapper API for hal and proto type is at hal_api_mac.h */
1748 enum rtw_hal_status
rtw_hal_mac_power_switch(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info,u8 on_off)1749 rtw_hal_mac_power_switch(struct rtw_phl_com_t *phl_com,
1750 struct hal_info_t *hal_info,
1751 u8 on_off)
1752 {
1753 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1754 //u8 pwr_state = 0;
1755
1756 /*pwr_state = hal_mac_get_pwr_state(mac);
1757 if(pwr_state != on_off)*/
1758
1759 if (mac->ops->pwr_switch(mac, on_off) != MACSUCCESS)
1760 return RTW_HAL_STATUS_FAILURE;
1761
1762 return RTW_HAL_STATUS_SUCCESS;
1763 }
1764
1765 #ifdef DBG_PHL_MAC_REG_RW
1766 #define HALPHY_BASE_OFFSET 0x10000
1767
rtw_hal_mac_reg_chk(struct rtw_hal_com_t * hal_com,u32 addr)1768 bool rtw_hal_mac_reg_chk(struct rtw_hal_com_t *hal_com, u32 addr)
1769 {
1770 struct hal_info_t *hal_info = hal_com->hal_priv;
1771 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1772 bool rst = true;
1773 u32 mac_rst;
1774
1775 if (addr & HALPHY_BASE_OFFSET)
1776 goto _exit;
1777
1778 if (mac != NULL && mac->ops->io_chk_access) {
1779 mac_rst = mac->ops->io_chk_access(mac, addr);
1780 if (mac_rst != MACSUCCESS) {
1781 rst = false;
1782 PHL_ERR("%s failed - addr(0x%08x) is err code(%d)\n",
1783 __func__, addr, mac_rst);
1784 _os_warn_on(1);
1785 }
1786 }
1787 _exit:
1788 return rst;
1789 }
1790 #endif
1791
1792 /* halmac wrapper API for hal and proto type is at hal_api_mac.h */
rtw_hal_mac_dbcc_pre_cfg(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info,u8 dbcc_en)1793 enum rtw_hal_status rtw_hal_mac_dbcc_pre_cfg(struct rtw_phl_com_t *phl_com,
1794 struct hal_info_t *hal_info,
1795 u8 dbcc_en)
1796 {
1797 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1798 struct mac_ax_trx_info trx_info = { 0 };
1799 struct mac_ax_pkt_drop_info drop_info = { 0 };
1800
1801 if (dbcc_en) {
1802 if (true == phl_com->dev_cap.tx_mu_ru)
1803 trx_info.trx_mode = MAC_AX_TRX_SW_MODE;
1804 else
1805 trx_info.trx_mode = MAC_AX_TRX_HW_MODE;
1806 trx_info.qta_mode = MAC_AX_QTA_DBCC;
1807
1808 if (mac->ops->dbcc_enable(mac, &trx_info, dbcc_en) != MACSUCCESS)
1809 return RTW_HAL_STATUS_FAILURE;
1810 } else {
1811 /* disable FW band 1 feature (H2C) */
1812
1813 drop_info.sel = MAC_AX_PKT_DROP_SEL_BAND;
1814 drop_info.band = MAC_AX_BAND_1;
1815
1816 if (mac->ops->pkt_drop(mac, &drop_info) != MACSUCCESS)
1817 return RTW_HAL_STATUS_FAILURE;
1818 }
1819 return RTW_HAL_STATUS_SUCCESS;
1820 }
1821
rtw_hal_mac_dbcc_cfg(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info,u8 dbcc_en)1822 enum rtw_hal_status rtw_hal_mac_dbcc_cfg(struct rtw_phl_com_t *phl_com,
1823 struct hal_info_t *hal_info,
1824 u8 dbcc_en)
1825 {
1826 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
1827 struct mac_ax_trx_info trx_info = { 0 };
1828
1829 if (dbcc_en) {
1830 /* Pass Throught, mac already enable at pre_cfg */
1831 } else {
1832 if (true == phl_com->dev_cap.tx_mu_ru)
1833 trx_info.trx_mode = MAC_AX_TRX_SW_MODE;
1834 else
1835 trx_info.trx_mode = MAC_AX_TRX_HW_MODE;
1836 trx_info.qta_mode = MAC_AX_QTA_SCC;
1837
1838 if (mac->ops->dbcc_enable(mac, &trx_info, dbcc_en) != MACSUCCESS)
1839 return RTW_HAL_STATUS_FAILURE;
1840 }
1841
1842 return RTW_HAL_STATUS_SUCCESS;
1843 }
1844
rtw_hal_mac_coex_init(struct rtw_hal_com_t * hal_com,u8 pta_mode,u8 direction)1845 u32 rtw_hal_mac_coex_init(struct rtw_hal_com_t *hal_com, u8 pta_mode, u8 direction)
1846 {
1847 struct hal_info_t *hal = hal_com->hal_priv;
1848 struct mac_ax_adapter *mac = hal_to_mac(hal);
1849 struct mac_ax_ops *ops = mac->ops;
1850 struct mac_ax_coex pta_para;
1851
1852 pta_para.pta_mode = pta_mode;
1853 pta_para.direction = direction;
1854
1855 return (ops->coex_init(mac, &pta_para));
1856 }
1857
rtw_hal_mac_coex_reg_read(struct rtw_hal_com_t * hal_com,u32 offset,u32 * value)1858 u32 rtw_hal_mac_coex_reg_read(struct rtw_hal_com_t *hal_com, u32 offset, u32 *value)
1859 {
1860 struct hal_info_t *hal = hal_com->hal_priv;
1861 struct mac_ax_adapter *mac = hal_to_mac(hal);
1862 struct mac_ax_ops *ops = mac->ops;
1863
1864 /* valid offset -> 0xda00~0xdaff */
1865 offset = offset & 0xff;
1866
1867 return (ops->coex_read(mac, offset, value));
1868 }
1869
rtw_hal_mac_set_scoreboard(struct rtw_hal_com_t * hal_com,u32 * value)1870 u32 rtw_hal_mac_set_scoreboard(struct rtw_hal_com_t *hal_com, u32 *value)
1871 {
1872 struct hal_info_t *hal = hal_com->hal_priv;
1873 struct mac_ax_adapter *mac = hal_to_mac(hal);
1874 struct mac_ax_ops *ops = mac->ops;
1875
1876 return (ops->set_hw_value(mac, MAC_AX_HW_SET_SCOREBOARD, value));
1877 }
1878
rtw_hal_mac_get_scoreboard(struct rtw_hal_com_t * hal_com,u32 * value)1879 u32 rtw_hal_mac_get_scoreboard(struct rtw_hal_com_t *hal_com, u32 *value)
1880 {
1881 struct hal_info_t *hal = hal_com->hal_priv;
1882 struct mac_ax_adapter *mac = hal_to_mac(hal);
1883 struct mac_ax_ops *ops = mac->ops;
1884
1885 return (ops->get_hw_value(mac, MAC_AX_HW_GET_SCOREBOARD, value));
1886 }
1887
rtw_hal_mac_set_grant(struct rtw_hal_com_t * hal_com,u8 * value)1888 u32 rtw_hal_mac_set_grant(struct rtw_hal_com_t *hal_com, u8 *value)
1889 {
1890 struct hal_info_t *hal = hal_com->hal_priv;
1891 struct mac_ax_adapter *mac = hal_to_mac(hal);
1892 struct mac_ax_ops *ops = mac->ops;
1893 struct mac_ax_coex_gnt gnt_val;
1894
1895 gnt_val.band0.gnt_bt_sw_en = value[0];
1896 gnt_val.band0.gnt_bt = value[1];
1897 gnt_val.band0.gnt_wl_sw_en = value[2];
1898 gnt_val.band0.gnt_wl = value[3];
1899
1900 gnt_val.band1.gnt_bt_sw_en = value[4];
1901 gnt_val.band1.gnt_bt = value[5];
1902 gnt_val.band1.gnt_wl_sw_en = value[6];
1903 gnt_val.band1.gnt_wl = value[7];
1904
1905 return (ops->set_hw_value(mac, MAC_AX_HW_SET_COEX_GNT, &gnt_val));
1906 }
1907
rtw_hal_mac_get_grant(struct rtw_hal_com_t * hal_com,u8 * value)1908 u32 rtw_hal_mac_get_grant(struct rtw_hal_com_t *hal_com, u8 *value)
1909 {
1910 struct hal_info_t *hal = hal_com->hal_priv;
1911 struct mac_ax_adapter *mac = hal_to_mac(hal);
1912 struct mac_ax_ops *ops = mac->ops;
1913
1914 return (ops->get_hw_value(mac, MAC_AX_HW_GET_COEX_GNT, value));
1915 }
1916
rtw_hal_mac_set_polluted(struct rtw_hal_com_t * hal_com,u8 band,u8 tx_val,u8 rx_val)1917 u32 rtw_hal_mac_set_polluted(struct rtw_hal_com_t *hal_com, u8 band, u8 tx_val, u8 rx_val)
1918 {
1919 struct hal_info_t *hal = hal_com->hal_priv;
1920 struct mac_ax_adapter *mac = hal_to_mac(hal);
1921 struct mac_ax_ops *ops = mac->ops;
1922 struct mac_ax_plt plt_val;
1923
1924 plt_val.band = band;
1925 plt_val.tx = tx_val;
1926 plt_val.rx = rx_val;
1927
1928 return (ops->set_hw_value(mac, MAC_AX_HW_SET_POLLUTED, &plt_val));
1929 }
1930
rtw_hal_mac_set_tx_time(struct rtw_hal_com_t * hal_com,u8 is_btc,u8 is_resume,u8 macid,u32 tx_time)1931 u32 rtw_hal_mac_set_tx_time(struct rtw_hal_com_t *hal_com, u8 is_btc, u8 is_resume, u8 macid, u32 tx_time)
1932 {
1933 struct hal_info_t *hal = hal_com->hal_priv;
1934 struct mac_ax_adapter *mac = hal_to_mac(hal);
1935 struct mac_ax_ops *ops = mac->ops;
1936 struct mac_ax_max_tx_time max_tx_time;
1937 u32 result = 0xffffffff;
1938
1939 max_tx_time.macid = macid;
1940 max_tx_time.is_cctrl = 1;
1941 max_tx_time.max_tx_time = tx_time;
1942
1943 if (is_btc && !is_resume) { /* for btc control tx time case */
1944 hal_com->btc_ctrl.tx_time = true;
1945 result = ops->set_hw_value(mac, MAC_AX_HW_SET_MAX_TX_TIME, &max_tx_time);
1946 } else if (is_btc && is_resume) { /* for btc release tx time case */
1947 result = ops->set_hw_value(mac, MAC_AX_HW_SET_MAX_TX_TIME, &max_tx_time);
1948 hal_com->btc_ctrl.tx_time = false;
1949 } else { /* not btc control case */
1950 if (hal_com->btc_ctrl.tx_time)
1951 return result;
1952 else
1953 result = ops->set_hw_value(mac, MAC_AX_HW_SET_MAX_TX_TIME, &max_tx_time);
1954 }
1955
1956 return result;
1957 }
1958
rtw_hal_mac_get_tx_time(struct rtw_hal_com_t * hal_com,u8 macid,u32 * tx_time)1959 u32 rtw_hal_mac_get_tx_time(struct rtw_hal_com_t *hal_com, u8 macid, u32 *tx_time)
1960 {
1961 struct hal_info_t *hal = hal_com->hal_priv;
1962 struct mac_ax_adapter *mac = hal_to_mac(hal);
1963 struct mac_ax_ops *ops = mac->ops;
1964 struct mac_ax_max_tx_time max_tx_time;
1965 u32 result;
1966
1967 max_tx_time.macid = macid;
1968 max_tx_time.is_cctrl = 1;
1969 max_tx_time.max_tx_time = *tx_time;
1970
1971 result = ops->get_hw_value(mac, MAC_AX_HW_GET_MAX_TX_TIME, &max_tx_time);
1972 *tx_time = max_tx_time.max_tx_time;
1973
1974 return (result);
1975 }
1976
rtw_hal_mac_set_tx_retry_limit(struct rtw_hal_com_t * hal_com,u8 is_btc,u8 is_resume,u8 macid,u8 tx_retry)1977 u32 rtw_hal_mac_set_tx_retry_limit(struct rtw_hal_com_t *hal_com, u8 is_btc, u8 is_resume, u8 macid, u8 tx_retry)
1978 {
1979 struct hal_info_t *hal = hal_com->hal_priv;
1980 struct mac_ax_adapter *mac = hal_to_mac(hal);
1981 struct mac_ax_ops *ops = mac->ops;
1982 struct mac_ax_cctl_rty_lmt_cfg tx_retry_limit;
1983 u32 result = 0xffffffff;
1984
1985 tx_retry_limit.macid = macid;
1986 tx_retry_limit.data_lmt_sel = 1;
1987 tx_retry_limit.data_lmt_val = tx_retry;
1988 tx_retry_limit.rts_lmt_sel = 0;
1989 tx_retry_limit.rts_lmt_val = 0;
1990
1991 if (is_btc && !is_resume) { /* for btc control tx time case */
1992 hal_com->btc_ctrl.tx_retry = true;
1993 result = ops->set_hw_value(mac, MAC_AX_HW_SET_CCTL_RTY_LMT, &tx_retry_limit);
1994 } else if (is_btc && is_resume) { /* for btc release tx time case */
1995 result = ops->set_hw_value(mac, MAC_AX_HW_SET_CCTL_RTY_LMT, &tx_retry_limit);
1996 hal_com->btc_ctrl.tx_retry = false;
1997 } else { /* not btc control case */
1998 if (hal_com->btc_ctrl.tx_retry)
1999 return result;
2000 else
2001 result = ops->set_hw_value(mac, MAC_AX_HW_SET_CCTL_RTY_LMT, &tx_retry_limit);
2002 }
2003
2004 return result;
2005 }
2006
rtw_hal_mac_get_tx_retry_limit(struct rtw_hal_com_t * hal_com,u8 macid,u8 * tx_retry)2007 u32 rtw_hal_mac_get_tx_retry_limit(struct rtw_hal_com_t *hal_com, u8 macid, u8 *tx_retry)
2008 {
2009 struct hal_info_t *hal = hal_com->hal_priv;
2010 struct mac_ax_adapter *mac = hal_to_mac(hal);
2011 struct mac_ax_ops *ops = mac->ops;
2012 struct mac_ax_rty_lmt tx_retry_limit;
2013 u32 result;
2014
2015 tx_retry_limit.macid = macid;
2016 tx_retry_limit.tx_cnt = *tx_retry;
2017 result = ops->get_hw_value(mac, MAC_AX_HW_GET_DATA_RTY_LMT, &tx_retry_limit);
2018 *tx_retry = (u8)tx_retry_limit.tx_cnt;
2019
2020 return (result);
2021 }
2022
rtw_hal_mac_get_bt_polt_cnt(struct rtw_hal_com_t * hal_com,u8 band,u16 * cnt)2023 u32 rtw_hal_mac_get_bt_polt_cnt(struct rtw_hal_com_t *hal_com, u8 band, u16 *cnt)
2024 {
2025 struct hal_info_t *hal = hal_com->hal_priv;
2026 struct mac_ax_adapter *mac = hal_to_mac(hal);
2027 struct mac_ax_ops *ops = mac->ops;
2028 struct mac_ax_bt_polt_cnt polt;
2029 u32 result;
2030
2031 polt.band = band;
2032 polt.cnt = *cnt;
2033 result = ops->get_hw_value(mac, MAC_AX_HW_GET_POLLUTED_CNT, &polt);
2034 *cnt = polt.cnt;
2035
2036 return (result);
2037 }
2038
rtw_hal_mac_set_coex_ctrl(struct rtw_hal_com_t * hal_com,u32 val)2039 u32 rtw_hal_mac_set_coex_ctrl(struct rtw_hal_com_t *hal_com, u32 val)
2040 {
2041 struct hal_info_t *hal = hal_com->hal_priv;
2042 struct mac_ax_adapter *mac = hal_to_mac(hal);
2043 struct mac_ax_ops *ops = mac->ops;
2044
2045 return (ops->set_hw_value(mac, MAC_AX_HW_SET_COEX_CTRL, &val));
2046 }
2047
rtw_hal_mac_get_coex_ctrl(struct rtw_hal_com_t * hal_com,u32 * val)2048 u32 rtw_hal_mac_get_coex_ctrl(struct rtw_hal_com_t *hal_com, u32* val)
2049 {
2050 struct hal_info_t *hal = hal_com->hal_priv;
2051 struct mac_ax_adapter *mac = hal_to_mac(hal);
2052 struct mac_ax_ops *ops = mac->ops;
2053
2054 return (ops->get_hw_value(mac, MAC_AX_HW_GET_COEX_CTRL, val));
2055 }
2056
rtw_hal_mac_coex_reg_write(struct rtw_hal_com_t * hal_com,u32 offset,u32 value)2057 u32 rtw_hal_mac_coex_reg_write(struct rtw_hal_com_t *hal_com, u32 offset, u32 value)
2058 {
2059 struct hal_info_t *hal = hal_com->hal_priv;
2060 struct mac_ax_adapter *mac = hal_to_mac(hal);
2061 struct mac_ax_ops *ops = mac->ops;
2062
2063 /* valid offset -> 0xda00~0xdaff */
2064 offset = offset & 0xff;
2065
2066 return (ops->coex_write(mac, offset, value));
2067 }
2068
2069 /* halmac wrapper API for hal and proto type is at hal_api_drv.h */
rtw_hal_mac_send_h2c(struct rtw_hal_com_t * hal_com,struct rtw_g6_h2c_hdr * hdr,u32 * pvalue)2070 u32 rtw_hal_mac_send_h2c(struct rtw_hal_com_t *hal_com,
2071 struct rtw_g6_h2c_hdr *hdr, u32 *pvalue)
2072 {
2073 struct hal_info_t *hal = hal_com->hal_priv;
2074 struct mac_ax_adapter *mac = hal_to_mac(hal);
2075 struct mac_ax_ops *ops = mac->ops;
2076 u32 mac_err = 0;
2077
2078 mac_err = ops->outsrc_h2c_common(mac, hdr, pvalue);
2079 if (mac_err != MACSUCCESS) {
2080 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2081 return RTW_HAL_STATUS_FAILURE;
2082 }
2083
2084 return RTW_HAL_STATUS_SUCCESS;
2085 }
2086
2087 static enum mac_ax_net_type
_rtype_to_mac_nettype(struct rtw_wifi_role_t * wifi_role)2088 _rtype_to_mac_nettype(struct rtw_wifi_role_t *wifi_role)
2089 {
2090 enum mac_ax_net_type net_type = MAC_AX_NET_TYPE_NO_LINK;
2091
2092 switch (wifi_role->type) {
2093 case PHL_RTYPE_STATION:
2094 case PHL_RTYPE_TDLS:
2095 net_type = (wifi_role->mstate == MLME_NO_LINK)
2096 ? MAC_AX_NET_TYPE_NO_LINK
2097 : MAC_AX_NET_TYPE_INFRA;
2098 break;
2099 case PHL_RTYPE_MONITOR:
2100 case PHL_RTYPE_P2P_DEVICE:
2101 net_type = MAC_AX_NET_TYPE_NO_LINK;
2102 break;
2103 case PHL_RTYPE_P2P_GC:
2104 net_type = MAC_AX_NET_TYPE_INFRA;
2105 break;
2106 case PHL_RTYPE_AP:
2107 case PHL_RTYPE_P2P_GO:
2108 case PHL_RTYPE_MESH:
2109 net_type = MAC_AX_NET_TYPE_AP;
2110 break;
2111 case PHL_RTYPE_ADHOC:
2112 case PHL_RTYPE_ADHOC_MASTER:
2113 net_type = MAC_AX_NET_TYPE_ADHOC;
2114 break;
2115 case PHL_RTYPE_NAN: /*TODO*/
2116 default:
2117 net_type = MAC_AX_NET_TYPE_NO_LINK;
2118 break;
2119 }
2120
2121 return net_type;
2122 }
2123
2124
2125 enum rtw_hal_status
rtw_hal_mac_port_init(struct hal_info_t * hal_info,struct rtw_wifi_role_t * wifi_role)2126 rtw_hal_mac_port_init(struct hal_info_t *hal_info,
2127 struct rtw_wifi_role_t *wifi_role)
2128 {
2129 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2130 struct mac_ax_port_init_para ppara = {0};
2131 struct rtw_phl_stainfo_t *phl_sta;
2132
2133 ppara.net_type = _rtype_to_mac_nettype(wifi_role);
2134 ppara.band_idx = wifi_role->hw_band;
2135 ppara.port_idx = wifi_role->hw_port;
2136 /*#ifdef CONFIG_AP*/
2137 ppara.hiq_win = wifi_role->hiq_win;
2138 ppara.dtim_period = wifi_role->dtim_period;
2139 ppara.mbid_num = wifi_role->mbid_num;/*max mbid number*/
2140 /*#endif - CONFIG_AP*/
2141
2142 if (ppara.net_type == MAC_AX_NET_TYPE_INFRA) {
2143 phl_sta = rtw_phl_get_stainfo_self(wifi_role->phl_com->phl_priv,
2144 wifi_role);
2145 if (phl_sta->asoc_cap.bcn_interval)
2146 ppara.bcn_interval = phl_sta->asoc_cap.bcn_interval;
2147 else
2148 ppara.bcn_interval = 100;
2149 ppara.bss_color = phl_sta->asoc_cap.bsscolor;
2150 } else if (ppara.net_type == MAC_AX_NET_TYPE_AP) {
2151 #ifdef RTW_PHL_BCN
2152 ppara.bcn_interval = (u16)wifi_role->bcn_cmn.bcn_interval;
2153 #else
2154 ppara.bcn_interval = 100;
2155 #endif
2156 ppara.bss_color = wifi_role->proto_role_cap.bsscolor;
2157 } else if (ppara.net_type == MAC_AX_NET_TYPE_ADHOC) {
2158 /* TODO */
2159 ppara.bcn_interval = 100;
2160 } else {
2161 /* other net_type, i.e. MAC_AX_NO_LINK */
2162 ppara.bcn_interval = 100;
2163 }
2164
2165 if (mac->ops->port_init(mac, &ppara) == MACSUCCESS)
2166 return RTW_HAL_STATUS_SUCCESS;
2167 return RTW_HAL_STATUS_FAILURE;
2168 }
2169
2170 enum rtw_hal_status
rtw_hal_mac_port_cfg(struct hal_info_t * hal_info,struct rtw_wifi_role_t * wifi_role,enum pcfg_type type,void * param)2171 rtw_hal_mac_port_cfg(struct hal_info_t *hal_info,
2172 struct rtw_wifi_role_t *wifi_role,
2173 enum pcfg_type type, void *param)
2174 {
2175 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2176 enum mac_ax_port_cfg_type ptype = MAC_AX_PCFG_FUNC_SW;
2177 struct mac_ax_port_cfg_para ppara = {0};
2178
2179 switch (type){
2180 case PCFG_FUNC_SW :
2181 ptype = MAC_AX_PCFG_FUNC_SW;
2182 break;
2183 case PCFG_TBTT_AGG :
2184 ptype = MAC_AX_PCFG_TBTT_AGG;
2185 break;
2186 case PCFG_TBTT_SHIFT :
2187 ptype = MAC_AX_PCFG_TBTT_SHIFT;
2188 break;
2189 case PCFG_HIQ_WIN :
2190 ptype = MAC_AX_PCFG_HIQ_WIN;
2191 break;
2192 case PCFG_HIQ_DTIM :
2193 ptype = MAC_AX_PCFG_HIQ_DTIM;
2194 break;
2195 case PCFG_BCN_INTERVAL :
2196 ptype = MAC_AX_PCFG_BCN_INTV;
2197 break;
2198 case PCFG_BSS_CLR :
2199 ptype = MAC_AX_PCFG_BSS_CLR;
2200 break;
2201 case PCFG_BCN_EN :
2202 ptype = MAC_AX_PCFG_TX_SW;
2203 break;
2204 default :
2205 PHL_ERR("Unknown port cfg type %d\n", type);
2206 goto _error;
2207 }
2208
2209 ppara.band = wifi_role->hw_band;
2210 ppara.port = wifi_role->hw_port;
2211 #ifdef RTW_PHL_BCN/*#ifdef CONFIG_AP*/
2212 ppara.mbssid_idx = wifi_role->hw_mbssid;
2213 #endif
2214 ppara.val = *(u32 *)param;
2215
2216 if (mac->ops->port_cfg(mac, ptype, &ppara) == MACSUCCESS)
2217 return RTW_HAL_STATUS_SUCCESS;
2218 _error:
2219 return RTW_HAL_STATUS_FAILURE;
2220 }
2221
2222 static enum mac_ax_wifi_role
_rtype_to_mac_wifirole(struct rtw_wifi_role_t * wifi_role)2223 _rtype_to_mac_wifirole(struct rtw_wifi_role_t *wifi_role)
2224 {
2225 enum mac_ax_wifi_role mac_wifi_role = MAC_AX_WIFI_ROLE_NONE;
2226
2227 switch (wifi_role->type) {
2228 case PHL_RTYPE_NONE:
2229 mac_wifi_role = MAC_AX_WIFI_ROLE_NONE;
2230 break;
2231 case PHL_RTYPE_STATION:
2232 case PHL_RTYPE_TDLS:
2233 mac_wifi_role = MAC_AX_WIFI_ROLE_STATION;
2234 break;
2235 case PHL_RTYPE_AP:
2236 mac_wifi_role = MAC_AX_WIFI_ROLE_AP;
2237 break;
2238 case PHL_RTYPE_VAP:
2239 mac_wifi_role = MAC_AX_WIFI_ROLE_VAP;
2240 break;
2241 case PHL_RTYPE_ADHOC:
2242 mac_wifi_role = MAC_AX_WIFI_ROLE_ADHOC;
2243 break;
2244 case PHL_RTYPE_ADHOC_MASTER:
2245 mac_wifi_role = MAC_AX_WIFI_ROLE_ADHOC_MASTER;
2246 break;
2247 case PHL_RTYPE_MESH:
2248 mac_wifi_role = MAC_AX_WIFI_ROLE_MESH;
2249 break;
2250 case PHL_RTYPE_MONITOR:
2251 mac_wifi_role = MAC_AX_WIFI_ROLE_MONITOR;
2252 break;
2253 case PHL_RTYPE_P2P_DEVICE:
2254 mac_wifi_role = MAC_AX_WIFI_ROLE_P2P_DEVICE;
2255 break;
2256 case PHL_RTYPE_P2P_GC:
2257 mac_wifi_role = MAC_AX_WIFI_ROLE_P2P_GC;
2258 break;
2259 case PHL_RTYPE_P2P_GO:
2260 mac_wifi_role = MAC_AX_WIFI_ROLE_P2P_GO;
2261 break;
2262 case PHL_RTYPE_NAN:
2263 mac_wifi_role = MAC_AX_WIFI_ROLE_NAN;
2264 break;
2265 default:
2266 mac_wifi_role = MAC_AX_WIFI_ROLE_STATION;
2267 break;
2268 }
2269
2270 return mac_wifi_role;
2271 }
2272
2273 static enum mac_ax_upd_mode
_hal_updmode_to_mac_upt_mode(enum phl_upd_mode mode)2274 _hal_updmode_to_mac_upt_mode(enum phl_upd_mode mode)
2275 {
2276 enum mac_ax_upd_mode upd_mode = MAC_AX_ROLE_INFO_CHANGE;
2277
2278 switch (mode) {
2279 case PHL_UPD_ROLE_CREATE:
2280 upd_mode = MAC_AX_ROLE_CREATE;
2281 break;
2282 case PHL_UPD_ROLE_REMOVE:
2283 upd_mode = MAC_AX_ROLE_REMOVE;
2284 break;
2285 case PHL_UPD_ROLE_TYPE_CHANGE:
2286 upd_mode = MAC_AX_ROLE_TYPE_CHANGE;
2287 break;
2288 case PHL_UPD_ROLE_INFO_CHANGE:
2289 case PHL_UPD_STA_INFO_CHANGE:
2290 upd_mode = MAC_AX_ROLE_INFO_CHANGE;
2291 break;
2292 case PHL_UPD_STA_CON_DISCONN:
2293 upd_mode = MAC_AX_ROLE_CON_DISCONN;
2294 break;
2295 case PHL_UPD_ROLE_MAX:
2296 /* fallthrough */
2297 default:
2298 PHL_ERR("error upt mode %d\n", mode);
2299 break;
2300 }
2301
2302 return upd_mode;
2303 }
2304
_hal_stainfo_to_macrinfo(struct hal_info_t * hal_info,struct rtw_phl_stainfo_t * sta,struct mac_ax_role_info * rinfo,enum phl_upd_mode mode,bool is_connect)2305 static void _hal_stainfo_to_macrinfo(struct hal_info_t *hal_info,
2306 struct rtw_phl_stainfo_t *sta,
2307 struct mac_ax_role_info *rinfo,
2308 enum phl_upd_mode mode,
2309 bool is_connect)
2310 {
2311 struct rtw_wifi_role_t *wifi_role = sta->wrole;
2312 void *drv = hal_to_drvpriv(hal_info);
2313 bool is_self = false;
2314
2315 rinfo->macid = (u8)sta->macid;
2316 rinfo->band = wifi_role->hw_band;
2317 rinfo->port = wifi_role->hw_port;
2318 rinfo->wmm = wifi_role->hw_wmm;
2319
2320 rinfo->net_type = _rtype_to_mac_nettype(wifi_role);
2321 rinfo->wifi_role = _rtype_to_mac_wifirole(wifi_role);
2322 rinfo->bcn_hit_cond = sta->bcn_hit_cond;
2323 rinfo->hit_rule = sta->hit_rule;
2324 rinfo->tsf_sync = wifi_role->hw_port;
2325 rinfo->aid = sta->aid;
2326 rinfo->wapi = sta->wapi;
2327 rinfo->sec_ent_mode = sta->sec_mode;
2328 rinfo->upd_mode = _hal_updmode_to_mac_upt_mode(mode);
2329 rinfo->opmode = (is_connect == true) ? MAC_AX_ROLE_CONNECT : MAC_AX_ROLE_DISCONN;
2330
2331 if (rinfo->net_type == MAC_AX_NET_TYPE_AP) {
2332 if (_os_mem_cmp(drv, wifi_role->mac_addr, sta->mac_addr, MAC_ALEN) == 0)
2333 is_self = true;
2334
2335 if(is_self == true) {
2336 rinfo->self_role = MAC_AX_SELF_ROLE_AP;
2337 } else {
2338 rinfo->self_role = MAC_AX_SELF_ROLE_AP_CLIENT;
2339 /* for ap client disconnect case,
2340 need to set no-link only for MAC_AX_ROLE_CON_DISCONN mode */
2341 if (is_connect == false && rinfo->upd_mode == MAC_AX_ROLE_CON_DISCONN)
2342 rinfo->net_type = MAC_AX_NET_TYPE_NO_LINK;
2343 /* only for client under AX SoftAP mode */
2344 if (sta->wmode & WLAN_MD_11AX)
2345 rinfo->tf_mac_padding = sta->asoc_cap.trig_padding;
2346 }
2347 } else if (rinfo->net_type == MAC_AX_NET_TYPE_INFRA || rinfo->net_type == MAC_AX_NET_TYPE_NO_LINK) {
2348 rinfo->self_role = MAC_AX_SELF_ROLE_CLIENT;
2349 }
2350
2351 if ((sta->wmode & WLAN_MD_11AX) && (wifi_role->mstate == MLME_LINKED)) {
2352 rinfo->trigger = sta->tf_trs;
2353 rinfo->bss_color = sta->asoc_cap.bsscolor;
2354 rinfo->addr_mask = (sta->addr_msk > 0)?MAC_AX_BYTE5:MAC_AX_MSK_NONE;
2355 rinfo->mask_sel = (sta->addr_sel > 0)?MAC_AX_BSSID_MSK:MAC_AX_NO_MSK;
2356 }
2357
2358 //TODO
2359 switch (rinfo->net_type) {
2360 case MAC_AX_NET_TYPE_NO_LINK :
2361 _os_mem_cpy(drv, rinfo->self_mac, wifi_role->mac_addr, MAC_ALEN);
2362 break;
2363 case MAC_AX_NET_TYPE_ADHOC :
2364 _os_mem_cpy(drv, rinfo->self_mac, wifi_role->mac_addr, MAC_ALEN);
2365 break;
2366 case MAC_AX_NET_TYPE_INFRA :
2367 rinfo->aid = sta->aid;
2368 _os_mem_cpy(drv, rinfo->self_mac, wifi_role->mac_addr, MAC_ALEN);
2369 _os_mem_cpy(drv, rinfo->target_mac, sta->mac_addr, MAC_ALEN);
2370 _os_mem_cpy(drv, rinfo->bssid, sta->mac_addr, MAC_ALEN);
2371 break;
2372 case MAC_AX_NET_TYPE_AP :
2373 _os_mem_cpy(drv, rinfo->self_mac, wifi_role->mac_addr, MAC_ALEN);
2374 _os_mem_cpy(drv, rinfo->target_mac, sta->mac_addr, MAC_ALEN);
2375 _os_mem_cpy(drv, rinfo->bssid, wifi_role->mac_addr, MAC_ALEN);
2376 break;
2377 default :
2378 break;
2379 }
2380
2381 }
2382
2383
2384 enum rtw_hal_status
rtw_hal_mac_role_sync(struct hal_info_t * hal_info,struct rtw_phl_stainfo_t * sta)2385 rtw_hal_mac_role_sync(struct hal_info_t *hal_info,
2386 struct rtw_phl_stainfo_t *sta)
2387 {
2388 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2389 struct mac_ax_role_info mac_rinfo = {0};
2390 u32 rst = 0;
2391
2392 _hal_stainfo_to_macrinfo(hal_info, sta, &mac_rinfo, PHL_UPD_ROLE_CREATE,
2393 false);
2394
2395 rst = mac->ops->role_sync(mac, &mac_rinfo);
2396
2397 if ((rst == MACSUCCESS) || (rst == MACSAMACID))
2398 return RTW_HAL_STATUS_SUCCESS;
2399
2400 return RTW_HAL_STATUS_FAILURE;
2401 }
2402
2403 enum rtw_hal_status
rtw_hal_mac_addr_cam_add_entry(struct hal_info_t * hal_info,struct rtw_phl_stainfo_t * sta)2404 rtw_hal_mac_addr_cam_add_entry(struct hal_info_t *hal_info,
2405 struct rtw_phl_stainfo_t *sta)
2406 {
2407 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2408 struct mac_ax_role_info mac_rinfo = {0};
2409 u32 rst = 0;
2410
2411 _hal_stainfo_to_macrinfo(hal_info, sta, &mac_rinfo, PHL_UPD_ROLE_CREATE, false);
2412
2413 rst = mac->ops->add_role(mac, &mac_rinfo);
2414
2415 if ((rst == MACSUCCESS) || (rst == MACSAMACID))
2416 return RTW_HAL_STATUS_SUCCESS;
2417
2418 return RTW_HAL_STATUS_FAILURE;
2419 }
2420
2421 enum rtw_hal_status
rtw_hal_mac_addr_cam_change_entry(struct hal_info_t * hal_info,struct rtw_phl_stainfo_t * sta,enum phl_upd_mode mode,bool is_connect)2422 rtw_hal_mac_addr_cam_change_entry(struct hal_info_t *hal_info,
2423 struct rtw_phl_stainfo_t *sta,
2424 enum phl_upd_mode mode,
2425 bool is_connect)
2426 {
2427 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2428 struct mac_ax_role_info mac_rinfo = {0};
2429
2430 _hal_stainfo_to_macrinfo(hal_info, sta, &mac_rinfo, mode, is_connect);
2431
2432 if (mac->ops->change_role(mac, &mac_rinfo) == MACSUCCESS)
2433 return RTW_HAL_STATUS_SUCCESS;
2434
2435 return RTW_HAL_STATUS_FAILURE;
2436 }
2437
2438 enum rtw_hal_status
rtw_hal_mac_addr_cam_set_aid(struct hal_info_t * hal_info,struct rtw_phl_stainfo_t * sta,u16 aid)2439 rtw_hal_mac_addr_cam_set_aid(struct hal_info_t *hal_info,
2440 struct rtw_phl_stainfo_t *sta,
2441 u16 aid)
2442 {
2443 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2444 struct mac_ax_role_info mac_rinfo = {0};
2445
2446 _hal_stainfo_to_macrinfo(hal_info, sta, &mac_rinfo, PHL_UPD_STA_INFO_CHANGE, true);
2447
2448 mac_rinfo.aid = aid;
2449
2450 if (mac->ops->change_role(mac, &mac_rinfo) == MACSUCCESS)
2451 return RTW_HAL_STATUS_SUCCESS;
2452
2453 return RTW_HAL_STATUS_FAILURE;
2454 }
2455
2456
2457 enum rtw_hal_status
rtw_hal_mac_addr_cam_del_entry(struct hal_info_t * hal_info,struct rtw_phl_stainfo_t * sta)2458 rtw_hal_mac_addr_cam_del_entry(struct hal_info_t *hal_info,
2459 struct rtw_phl_stainfo_t *sta)
2460 {
2461 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2462
2463 if (mac->ops->remove_role(mac, (u8)sta->macid) == MACSUCCESS)
2464 return RTW_HAL_STATUS_SUCCESS;
2465 return RTW_HAL_STATUS_FAILURE;
2466 }
2467
2468 enum rtw_hal_status
rtw_hal_mac_add_key(struct hal_info_t * hal_info,u8 macid,u8 type,u8 ext_key,u8 spp,u8 keyid,u8 keytype,u8 * keybuf)2469 rtw_hal_mac_add_key(struct hal_info_t *hal_info, u8 macid, u8 type, u8 ext_key,
2470 u8 spp, u8 keyid, u8 keytype, u8 *keybuf)
2471 {
2472 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2473 void *drv = hal_to_drvpriv(hal_info);
2474 struct mac_ax_sec_cam_info sec_cam;
2475 u32 mac_err;
2476
2477 sec_cam.type = type;
2478 sec_cam.ext_key = ext_key;
2479 sec_cam.spp_mode = spp;
2480 sec_cam.len = 20;
2481 sec_cam.offset = 0;
2482 _os_mem_set(drv, &sec_cam.key, 0, sizeof(sec_cam.key));
2483
2484 switch (type)
2485 {
2486 case RTW_ENC_WEP40:
2487 _os_mem_cpy(drv, &sec_cam.key, keybuf, 5);
2488 break;
2489 case RTW_ENC_WEP104:
2490 _os_mem_cpy(drv, &sec_cam.key, keybuf, 13);
2491 break;
2492 case RTW_ENC_TKIP:
2493 case RTW_ENC_CCMP:
2494 case RTW_ENC_CCMP256:
2495 case RTW_ENC_GCMP:
2496 case RTW_ENC_GCMP256:
2497 case RTW_ENC_BIP_CCMP128:
2498 case RTW_ENC_WAPI:
2499 case RTW_ENC_GCMSMS4:
2500 _os_mem_cpy(drv, &sec_cam.key, keybuf, 16);
2501 break;
2502 default:
2503 break;
2504 }
2505
2506 mac_err = mac->ops->sta_add_key(mac, &sec_cam, macid, keyid, keytype);
2507
2508 if (mac_err != MACSUCCESS) {
2509 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2510 return RTW_HAL_STATUS_FAILURE;
2511 }
2512
2513 return RTW_HAL_STATUS_SUCCESS;
2514 }
2515
2516 enum rtw_hal_status
rtw_hal_mac_delete_key(struct hal_info_t * hal_info,u8 macid,u8 type,u8 ext_key,u8 spp,u8 keyid,u8 keytype)2517 rtw_hal_mac_delete_key(struct hal_info_t *hal_info, u8 macid, u8 type,
2518 u8 ext_key, u8 spp, u8 keyid, u8 keytype)
2519 {
2520 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2521 u32 mac_err;
2522
2523 mac_err = mac->ops->sta_del_key(mac, macid, keyid, keytype);
2524
2525 if (mac_err != MACSUCCESS) {
2526 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2527 return RTW_HAL_STATUS_FAILURE;
2528 }
2529
2530 return RTW_HAL_STATUS_SUCCESS;
2531 }
2532
2533 u32
rtw_hal_mac_search_key_idx(struct hal_info_t * hal_info,u8 macid,u8 keyid,u8 keytype)2534 rtw_hal_mac_search_key_idx(struct hal_info_t *hal_info, u8 macid,
2535 u8 keyid, u8 keytype)
2536 {
2537 u32 sec_cam_idx;
2538 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2539
2540 sec_cam_idx = mac->ops->sta_search_key_idx(mac, macid, keyid, keytype);
2541
2542 return sec_cam_idx;
2543 }
2544
2545 u32
rtw_hal_mac_ser_reset_wdt_intr(struct hal_info_t * hal_info)2546 rtw_hal_mac_ser_reset_wdt_intr(struct hal_info_t *hal_info)
2547 {
2548 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2549 struct mac_ax_ops *ops = mac->ops;
2550 u8 dummyval = 0;
2551 u32 result = 0xffffffff;
2552
2553 result = ops->set_hw_value(mac, MAC_AX_HW_SET_WDT_ISR_RST, &dummyval);
2554
2555 return result;
2556 }
2557
2558 enum rtw_hal_status
rtw_hal_mac_ser_get_error_status(struct hal_info_t * hal_info,u32 * err)2559 rtw_hal_mac_ser_get_error_status(struct hal_info_t *hal_info, u32 *err)
2560 {
2561 u32 mac_err = 0;
2562 enum mac_ax_err_info err_info = 0;
2563 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2564
2565 mac_err = mac->ops->get_err_status(mac, &err_info);
2566 if (mac_err != MACSUCCESS) {
2567 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2568 return RTW_HAL_STATUS_FAILURE;
2569 }
2570
2571 *err = err_info;
2572
2573 return RTW_HAL_STATUS_SUCCESS;
2574 }
2575
2576 enum rtw_hal_status
rtw_hal_mac_ser_set_error_status(struct hal_info_t * hal_info,enum RTW_PHL_SER_RCVY_STEP err)2577 rtw_hal_mac_ser_set_error_status(struct hal_info_t *hal_info, enum RTW_PHL_SER_RCVY_STEP err)
2578 {
2579 u32 mac_err = 0;
2580 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2581 u32 err_info = 0;
2582
2583 if (err == RTW_PHL_SER_L1_DISABLE_EN) {
2584 err_info = MAC_AX_ERR_L1_DISABLE_EN;
2585 } else if (err == RTW_PHL_SER_L1_RCVY_EN) {
2586 err_info = MAC_AX_ERR_L1_RCVY_EN;
2587 } else if (err == RTW_PHL_SER_L0_CFG_NOTIFY) {
2588 err_info = MAC_AX_ERR_L0_CFG_NOTIFY;
2589 } else if (err == RTW_PHL_SER_L0_CFG_DIS_NOTIFY) {
2590 err_info = MAC_AX_ERR_L0_CFG_DIS_NOTIFY;
2591 } else if (err == RTW_PHL_SER_L0_CFG_HANDSHAKE) {
2592 err_info = MAC_AX_ERR_L0_CFG_HANDSHAKE;
2593 } else if (err == RTW_PHL_SER_L0_RCVY_EN) {
2594 err_info = MAC_AX_ERR_L0_RCVY_EN;
2595 }
2596 PHL_INFO("%s : error info to mac 0x%x.\n", __func__, err_info);
2597
2598 mac_err = mac->ops->set_err_status(mac, err_info);
2599 if (mac_err != MACSUCCESS) {
2600 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2601 return RTW_HAL_STATUS_FAILURE;
2602 }
2603
2604 return RTW_HAL_STATUS_SUCCESS;
2605 }
2606
2607 enum rtw_hal_status
rtw_hal_mac_trigger_cmac_err(struct hal_info_t * hal_info)2608 rtw_hal_mac_trigger_cmac_err(struct hal_info_t *hal_info)
2609 {
2610 u32 mac_err = 0;
2611 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2612
2613 mac_err = mac->ops->trigger_cmac_err(mac);
2614 if (mac_err != MACSUCCESS) {
2615 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2616 return RTW_HAL_STATUS_FAILURE;
2617 }
2618
2619 return RTW_HAL_STATUS_SUCCESS;
2620 }
2621
2622 enum rtw_hal_status
rtw_hal_mac_trigger_dmac_err(struct hal_info_t * hal_info)2623 rtw_hal_mac_trigger_dmac_err(struct hal_info_t *hal_info)
2624 {
2625 u32 mac_err = 0;
2626 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2627
2628 mac_err = mac->ops->trigger_dmac_err(mac);
2629 if (mac_err != MACSUCCESS) {
2630 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2631 return RTW_HAL_STATUS_FAILURE;
2632 }
2633
2634 return RTW_HAL_STATUS_SUCCESS;
2635 }
2636
2637 enum rtw_hal_status
rtw_hal_mac_lv1_rcvy(struct hal_info_t * hal_info,enum rtw_phl_ser_lv1_recv_step step)2638 rtw_hal_mac_lv1_rcvy(struct hal_info_t *hal_info, enum rtw_phl_ser_lv1_recv_step step)
2639 {
2640 u32 mac_err = 0;
2641 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2642
2643 mac_err = mac->ops->lv1_rcvy(mac, step);
2644 if (mac_err != MACSUCCESS) {
2645 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2646 return RTW_HAL_STATUS_FAILURE;
2647 }
2648
2649 return RTW_HAL_STATUS_SUCCESS;
2650 }
2651
rtw_hal_mac_ser_ctrl(struct hal_info_t * hal_info,bool en)2652 enum rtw_hal_status rtw_hal_mac_ser_ctrl(struct hal_info_t *hal_info, bool en)
2653 {
2654 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2655 u32 mac_err = 0;
2656 enum mac_ax_func_sw cfg = (en == true) ? MAC_AX_FUNC_EN : MAC_AX_FUNC_DIS;
2657 u32 start_t = 0;
2658
2659 start_t = _os_get_cur_time_us();
2660
2661 PHL_INFO("%s\n", __func__);
2662
2663 mac_err = mac->ops->ser_ctrl(mac, cfg);
2664
2665 if (mac_err != MACSUCCESS) {
2666 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
2667 return RTW_HAL_STATUS_FAILURE;
2668 }
2669
2670 PHL_INFO("%s : %s ser success with %d us.\n", __func__,
2671 (en ? "start" : "stop"), phl_get_passing_time_us(start_t));
2672
2673 return RTW_HAL_STATUS_SUCCESS;
2674 }
2675
2676 enum rtw_hal_status
rtw_hal_mac_poll_hw_tx_done(struct hal_info_t * hal_info)2677 rtw_hal_mac_poll_hw_tx_done(struct hal_info_t *hal_info)
2678 {
2679 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "poll hw tx done is not supported now!\n");
2680 return RTW_HAL_STATUS_MAC_API_FAILURE;
2681 }
2682
2683 enum rtw_hal_status
rtw_hal_mac_hw_tx_resume(struct hal_info_t * hal_info)2684 rtw_hal_mac_hw_tx_resume(struct hal_info_t *hal_info)
2685 {
2686 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "resume hw tx is not supported now!\n");
2687 return RTW_HAL_STATUS_MAC_API_FAILURE;
2688 }
2689
2690 enum rtw_hal_status
rtw_hal_mac_poll_hw_rx_done(struct hal_info_t * hal_info)2691 rtw_hal_mac_poll_hw_rx_done(struct hal_info_t *hal_info)
2692 {
2693 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "poll hw rx done is not supported now!\n");
2694 return RTW_HAL_STATUS_MAC_API_FAILURE;
2695 }
2696
2697 enum rtw_hal_status
rtw_hal_mac_hw_rx_resume(struct hal_info_t * hal_info)2698 rtw_hal_mac_hw_rx_resume(struct hal_info_t *hal_info)
2699 {
2700 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "resume hw rx is not supported now!\n");
2701 return RTW_HAL_STATUS_MAC_API_FAILURE;
2702 }
2703
2704
2705 #define FW_PLE_SIZE 0x800
2706 #define FW_PLE_SEGMENT_SIZE 512 /*Because PHL_PRINT have prefix 5 bytes "PHL: "*/
2707
2708 void
_hal_fw_dbg_dump(struct hal_info_t * hal_info,u8 * buffer,u16 bufsize)2709 _hal_fw_dbg_dump(struct hal_info_t *hal_info, u8 *buffer, u16 bufsize)
2710 {
2711 char str[FW_PLE_SEGMENT_SIZE + 1] = {0};
2712 u16 i = 0, ofst = 0;
2713
2714 for (ofst = 0; ofst < bufsize; ofst += FW_PLE_SEGMENT_SIZE) {
2715 for (i = 0; i < FW_PLE_SEGMENT_SIZE; i++)
2716 _os_snprintf(str + i, 2, "%c", buffer[i + ofst]);
2717 PHL_PRINT("%s\n", str);
2718 _os_mem_set(hal_to_drvpriv(hal_info), str, 0, sizeof(str));
2719 }
2720 }
2721
2722 enum rtw_hal_status
rtw_hal_mac_dump_fw_rsvd_ple(struct hal_info_t * hal_info)2723 rtw_hal_mac_dump_fw_rsvd_ple(struct hal_info_t *hal_info)
2724 {
2725 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2726 u8 *buffer = NULL;
2727 u16 bufSize = FW_PLE_SIZE;
2728
2729 if(mac->ops->dump_fw_rsvd_ple(mac, &buffer) != 0) {
2730 PHL_ERR("%s fail!\n", __func__);
2731 return RTW_HAL_STATUS_FAILURE;
2732 }
2733
2734 if (buffer != NULL) {
2735 PHL_PRINT("=======================\n");
2736 PHL_PRINT("Start to dump fw rsvd ple :\n\n");
2737 _hal_fw_dbg_dump(hal_info, buffer, bufSize);
2738 PHL_PRINT("\n=======================\n");
2739 _os_mem_free(hal_info->hal_com->drv_priv, buffer, bufSize);
2740 } else {
2741 PHL_ERR("dump_fw_rsvd_ple return invalid buffer!\n");
2742 }
2743
2744 return RTW_HAL_STATUS_SUCCESS;
2745 }
2746
2747
2748 /*
2749 * halmac wrapper API for hal and proto type is at hal_api_mac.h
2750 * init HW scope or start HW scope?
2751 */
2752 enum rtw_hal_status
rtw_hal_mac_init_mac(void * mac,struct hal_init_info_t * init_info)2753 rtw_hal_mac_init_mac(void *mac,struct hal_init_info_t *init_info)
2754 {
2755 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
2756 struct mac_ax_ops *hal_mac_ops = mac_info->ops;
2757 struct mac_ax_trx_info trx_info;
2758
2759 trx_info.trx_mode = init_info->trx_info.trx_mode;
2760 trx_info.qta_mode = init_info->trx_info.qta_mode;
2761
2762 if (hal_mac_ops->sys_init(mac_info))
2763 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
2764
2765 if (hal_mac_ops->trx_init(mac_info, &trx_info))
2766 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
2767
2768 return RTW_HAL_STATUS_SUCCESS;
2769 }
2770
2771 enum rtw_hal_status
rtw_hal_mac_trx_init(void * mac,struct hal_init_info_t * init_info)2772 rtw_hal_mac_trx_init(void *mac, struct hal_init_info_t *init_info)
2773 {
2774 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
2775 struct mac_ax_ops *hal_mac_ops = mac_info->ops;
2776 struct mac_ax_trx_info trx_info;
2777
2778 trx_info.trx_mode = init_info->trx_info.trx_mode;
2779 trx_info.qta_mode = init_info->trx_info.qta_mode;
2780
2781 if (hal_mac_ops->trx_init(mac_info, &trx_info))
2782 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
2783
2784 return RTW_HAL_STATUS_SUCCESS;
2785 }
2786
_hal_mac_get_ofld_cap(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info)2787 void _hal_mac_get_ofld_cap(struct rtw_phl_com_t *phl_com, struct hal_info_t *hal_info)
2788 {
2789 #ifdef CONFIG_FW_IO_OFLD_SUPPORT
2790 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2791 u32 mac_status = 0;
2792
2793 mac_status = mac->ops->get_hw_value(mac, MAC_AX_HW_GET_FW_CAP,
2794 &(hal_info->hal_com->dev_hw_cap.fw_cap.offload_cap));
2795 if (mac_status == MACSUCCESS) {
2796 phl_com->dev_cap.fw_cap.offload_cap = phl_com->dev_sw_cap.fw_cap.offload_cap &
2797 hal_info->hal_com->dev_hw_cap.fw_cap.offload_cap;
2798 PHL_INFO("%s: sw ofld cap: 0x%x, fw ofld cap 0x%x, final ofld cap: 0x%x!\n", __func__,
2799 phl_com->dev_sw_cap.fw_cap.offload_cap,
2800 hal_info->hal_com->dev_hw_cap.fw_cap.offload_cap,
2801 phl_com->dev_cap.fw_cap.offload_cap);
2802 } else {
2803 hal_info->hal_com->dev_hw_cap.fw_cap.offload_cap = 0;
2804 phl_com->dev_cap.fw_cap.offload_cap = 0;
2805 PHL_WARN("%s: fw ofld cap not enabled.\n", __func__);
2806 }
2807 #else
2808 hal_info->hal_com->dev_hw_cap.fw_cap.offload_cap = 0;
2809 phl_com->dev_cap.fw_cap.offload_cap = 0;
2810 PHL_INFO("%s: fw ofld cap not enabled.\n", __func__);
2811 #endif
2812 }
2813
2814 enum rtw_hal_status
rtw_hal_mac_hal_init(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info,struct hal_init_info_t * init_info)2815 rtw_hal_mac_hal_init(struct rtw_phl_com_t *phl_com,
2816 struct hal_info_t *hal_info,
2817 struct hal_init_info_t *init_info)
2818 {
2819 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
2820 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2821 struct rtw_fw_info_t *fw_info = &phl_com->fw_info;
2822 struct hal_ops_t *hal_ops = hal_get_ops(hal_info);
2823 struct mac_ax_fwdl_info fwdl_info;
2824 u32 mac_status = 0;
2825 enum rtw_fw_type fw_type = RTW_FW_MAX;
2826 #ifdef CONFIG_PHL_CSUM_OFFLOAD_RX
2827 u8 tx_chksum_offload = 0;
2828 u8 rx_chksum_offload = 0;
2829 #endif
2830 FUNCIN_WSTS(hstatus);
2831
2832 #ifdef PHL_FEATURE_NIC
2833 fw_type = RTW_FW_NIC;
2834 #elif defined(PHL_FEATURE_AP)
2835 fw_type = RTW_FW_AP;
2836 #else
2837 fw_type = RTW_FW_MAX;
2838 #endif
2839
2840 hstatus = hal_ops->hal_cfg_fw(phl_com, hal_info, init_info->ic_name, fw_type);
2841 if(RTW_HAL_STATUS_SUCCESS != hstatus) {
2842 PHL_ERR("%s : Cfg FW Failed: %d!\n", __func__, hstatus);
2843 return hstatus;
2844 }
2845 /* fwdl_info */
2846 fwdl_info.fw_en = fw_info->fw_en;
2847 fwdl_info.dlram_en = fw_info->dlram_en;
2848 fwdl_info.dlrom_en = fw_info->dlrom_en;
2849 fwdl_info.ram_buff = fw_info->ram_buff;
2850 fwdl_info.ram_size = fw_info->ram_size;
2851 fwdl_info.rom_buff = fw_info->rom_buff;
2852 fwdl_info.rom_size = fw_info->rom_size;
2853 fwdl_info.fw_cat = fw_info->fw_type;
2854
2855 if(fw_info->fw_src == RTW_FW_SRC_EXTNAL)
2856 fwdl_info.fw_from_hdr = 0;
2857 else
2858 fwdl_info.fw_from_hdr = 1;
2859
2860 mac_status = mac->ops->hal_init(mac, &init_info->trx_info, &fwdl_info, &init_info->intf_info);
2861
2862 if (mac_status == MACSUCCESS) {
2863 hstatus = RTW_HAL_STATUS_SUCCESS;
2864 hal_mac_print_fw_version(hal_info);
2865 } else {
2866 hstatus = RTW_HAL_STATUS_MAC_INIT_FAILURE;
2867 PHL_ERR("%s : mac_status %d!\n", __func__, mac_status);
2868 }
2869 _hal_mac_get_ofld_cap(phl_com, hal_info);
2870 #ifdef CONFIG_PHL_CSUM_OFFLOAD_RX
2871 rx_chksum_offload = 1;
2872 mac_status = mac->ops->tcpip_chksum_ofd(mac, tx_chksum_offload, rx_chksum_offload);
2873 if (mac_status != MACSUCCESS)
2874 PHL_ERR("%s : tcpip_chksum_ofd mac_status %d!!!!!!!\n", __func__, mac_status);
2875 #endif
2876
2877 FUNCOUT_WSTS(hstatus);
2878
2879 return hstatus;
2880 }
2881
2882 enum rtw_hal_status
rtw_hal_mac_hal_fast_init(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info,struct hal_init_info_t * init_info)2883 rtw_hal_mac_hal_fast_init(struct rtw_phl_com_t *phl_com,
2884 struct hal_info_t *hal_info,
2885 struct hal_init_info_t *init_info)
2886 {
2887 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
2888 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2889 struct rtw_fw_info_t *fw_info = &phl_com->fw_info;
2890 struct hal_ops_t *hal_ops = hal_get_ops(hal_info);
2891 struct mac_ax_fwdl_info fwdl_info;
2892 u32 mac_status = 0;
2893 enum rtw_fw_type fw_type = RTW_FW_MAX;
2894
2895 FUNCIN_WSTS(hstatus);
2896
2897 #ifdef PHL_FEATURE_NIC
2898 fw_type = RTW_FW_NIC;
2899 #elif defined(PHL_FEATURE_AP)
2900 fw_type = RTW_FW_AP;
2901 #else
2902 fw_type = RTW_FW_MAX;
2903 #endif
2904 hstatus = hal_ops->hal_cfg_fw(phl_com, hal_info, init_info->ic_name, fw_type);
2905 if(RTW_HAL_STATUS_SUCCESS != hstatus) {
2906 PHL_ERR("%s : Cfg FW Failed: %d!\n", __func__, hstatus);
2907 return hstatus;
2908 }
2909
2910 /* fwdl_info */
2911 fwdl_info.fw_en = fw_info->fw_en;
2912 fwdl_info.dlram_en = fw_info->dlram_en;
2913 fwdl_info.dlrom_en = fw_info->dlrom_en;
2914 fwdl_info.ram_buff = fw_info->ram_buff;
2915 fwdl_info.ram_size = fw_info->ram_size;
2916 fwdl_info.rom_buff = fw_info->rom_buff;
2917 fwdl_info.rom_size = fw_info->rom_size;
2918 fwdl_info.fw_cat = fw_info->fw_type;
2919
2920 if(fw_info->fw_src == RTW_FW_SRC_EXTNAL)
2921 fwdl_info.fw_from_hdr = 0;
2922 else
2923 fwdl_info.fw_from_hdr = 1;
2924
2925 mac_status = mac->ops->hal_fast_init(mac, &init_info->trx_info, &fwdl_info, &init_info->intf_info);
2926 if (mac_status == MACSUCCESS)
2927 hstatus = RTW_HAL_STATUS_SUCCESS;
2928 else {
2929
2930 hstatus = RTW_HAL_STATUS_HAL_INIT_FAILURE;
2931 PHL_ERR("%s : mac_status %d!\n", __func__, mac_status);
2932 }
2933
2934 FUNCOUT_WSTS(hstatus);
2935
2936 return hstatus;
2937 }
2938
2939 enum rtw_hal_status
rtw_hal_mac_hal_deinit(struct rtw_phl_com_t * phl_com,struct hal_info_t * hal_info)2940 rtw_hal_mac_hal_deinit(struct rtw_phl_com_t *phl_com, struct hal_info_t *hal_info)
2941 {
2942 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
2943 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2944 u32 mac_status = 0;
2945
2946 mac_status = mac->ops->hal_deinit(mac);
2947
2948 if (mac_status == MACSUCCESS)
2949 hstatus = RTW_HAL_STATUS_SUCCESS;
2950 else
2951 PHL_ERR("%s : mac_status %d!\n", __func__, mac_status);
2952
2953 FUNCOUT_WSTS(hstatus);
2954
2955 return hstatus;
2956 }
2957
2958 enum rtw_hal_status
rtw_hal_mac_chk_allq_empty(struct hal_info_t * hal_info,u8 * empty)2959 rtw_hal_mac_chk_allq_empty(struct hal_info_t *hal_info, u8 *empty)
2960 {
2961 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2962 struct mac_ax_ops *hal_mac_ops = mac->ops;
2963
2964 if (hal_mac_ops->chk_allq_empty(mac, empty))
2965 return RTW_HAL_STATUS_FAILURE;
2966
2967 return RTW_HAL_STATUS_SUCCESS;
2968 }
2969
2970 #ifdef CONFIG_WOWLAN
2971 enum rtw_hal_status
rtw_hal_mac_cfg_wow_sleep(struct hal_info_t * hal_info,u8 sleep)2972 rtw_hal_mac_cfg_wow_sleep(struct hal_info_t *hal_info, u8 sleep)
2973 {
2974 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2975 struct mac_ax_ops *hal_mac_ops = mac->ops;
2976
2977 if (hal_mac_ops->cfg_wow_sleep(mac,sleep))
2978 return RTW_HAL_STATUS_FAILURE;
2979
2980 return RTW_HAL_STATUS_SUCCESS;
2981 }
2982
2983 enum rtw_hal_status
rtw_hal_mac_get_wow_fw_status(struct hal_info_t * hal_info,u8 * status,u8 func_en)2984 rtw_hal_mac_get_wow_fw_status(struct hal_info_t *hal_info, u8 *status, u8 func_en)
2985 {
2986 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
2987 struct mac_ax_ops *hal_mac_ops = mac->ops;
2988
2989 if (hal_mac_ops->get_wow_fw_status(mac,status, func_en))
2990 return RTW_HAL_STATUS_FAILURE;
2991
2992 return RTW_HAL_STATUS_SUCCESS;
2993 }
2994
2995 enum rtw_hal_status
rtw_hal_mac_cfg_keep_alive(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_keep_alive_info * cfg)2996 rtw_hal_mac_cfg_keep_alive(struct hal_info_t *hal_info, u16 macid, u8 en,
2997 struct rtw_keep_alive_info *cfg)
2998 {
2999 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3000 struct mac_ax_ops *hal_mac_ops = mac->ops;
3001 struct mac_ax_keep_alive_info info = {0};
3002
3003 if (en && cfg == NULL)
3004 return RTW_HAL_STATUS_FAILURE;
3005
3006 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3007
3008 if (en) {
3009 info.keepalive_en = cfg->keep_alive_en;
3010 info.period = cfg->keep_alive_period;
3011 info.packet_id = cfg->null_pkt_id;
3012 }
3013
3014 if (hal_mac_ops->cfg_keepalive(mac, (u8)macid, &info))
3015 return RTW_HAL_STATUS_FAILURE;
3016
3017 return RTW_HAL_STATUS_SUCCESS;
3018 }
3019
3020 enum rtw_hal_status
rtw_hal_mac_cfg_disc_dec(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_disc_det_info * cfg)3021 rtw_hal_mac_cfg_disc_dec(struct hal_info_t *hal_info, u16 macid, u8 en, struct rtw_disc_det_info *cfg)
3022 {
3023 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3024 struct mac_ax_ops *hal_mac_ops = mac->ops;
3025 struct mac_ax_disconnect_det_info info = {0};
3026
3027 if (en && cfg == NULL)
3028 return RTW_HAL_STATUS_FAILURE;
3029
3030 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3031
3032 if (en) {
3033 info.disconnect_detect_en = cfg->disc_det_en;
3034 info.disconnect_en = (cfg->disc_wake_en == 1) ? 0 : 1;
3035 info.check_period = cfg->check_period;
3036 info.try_pkt_count = cfg->try_pkt_count;
3037 info.tryok_bcnfail_count_en = cfg->cnt_bcn_lost_en;
3038 info.tryok_bcnfail_count_limit = cfg->cnt_bcn_lost_limit;
3039 }
3040
3041 if (hal_mac_ops->cfg_disconnect_det(mac, (u8)macid, &info))
3042 return RTW_HAL_STATUS_FAILURE;
3043
3044 return RTW_HAL_STATUS_SUCCESS;
3045 }
3046
3047 enum rtw_hal_status
rtw_hal_mac_cfg_dev2hst_gpio(struct hal_info_t * hal_info,u8 en,struct rtw_wow_gpio_info * cfg)3048 rtw_hal_mac_cfg_dev2hst_gpio(struct hal_info_t *hal_info, u8 en, struct rtw_wow_gpio_info *cfg)
3049 {
3050 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3051 struct mac_ax_ops *hal_mac_ops = mac->ops;
3052 struct mac_ax_dev2hst_gpio_info info = {0};
3053
3054 if (en) {
3055 if (!cfg)
3056 return RTW_HAL_STATUS_FAILURE;
3057
3058 _os_mem_cpy(hal_to_drvpriv(hal_info), &info,
3059 &cfg->d2h_gpio_info,
3060 sizeof(struct rtw_dev2hst_gpio_info));
3061 }
3062
3063 if (hal_mac_ops->cfg_dev2hst_gpio(mac, &info))
3064 return RTW_HAL_STATUS_FAILURE;
3065
3066 return RTW_HAL_STATUS_SUCCESS;
3067 }
3068
3069 enum rtw_hal_status
rtw_hal_mac_cfg_wow_wake(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_wow_wake_info * cfg)3070 rtw_hal_mac_cfg_wow_wake(struct hal_info_t *hal_info, u16 macid, u8 en, struct rtw_wow_wake_info *cfg)
3071 {
3072 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3073 struct mac_ax_ops *hal_mac_ops = mac->ops;
3074 struct mac_ax_wow_wake_info info = {0};
3075 struct mac_ax_remotectrl_info_parm_ *content = NULL;
3076 struct mac_ax_remotectrl_info_parm_ param;
3077
3078 if (en && cfg == NULL)
3079 return RTW_HAL_STATUS_FAILURE;
3080
3081 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3082
3083 if (en) {
3084 info.wow_en = cfg->wow_en;
3085 info.drop_all_pkt = cfg->drop_all_pkt;
3086 info.rx_parse_after_wake = cfg->rx_parse_after_wake;
3087 info.pairwise_sec_algo = cfg->pairwise_sec_algo;
3088 info.group_sec_algo = cfg->group_sec_algo;
3089 /*
3090 info.bip_sec_algo = cfg->bip_sec_algo;
3091 */
3092 info.pattern_match_en = cfg->pattern_match_en;
3093 info.magic_en = cfg->magic_pkt_en;
3094 info.hw_unicast_en = cfg->hw_unicast_en;
3095 info.fw_unicast_en = cfg->fw_unicast_en;
3096 info.deauth_wakeup = cfg->deauth_wakeup;
3097 info.rekey_wakeup = cfg->rekey_wakeup;
3098 info.eap_wakeup = cfg->eap_wakeup;
3099 info.all_data_wakeup = cfg->all_data_wakeup;
3100
3101 if (cfg->pairwise_sec_algo) {
3102 param.validcheck = cfg->remote_wake_ctrl_info.valid_check;
3103 param.symbolchecken = cfg->remote_wake_ctrl_info.symbol_check_en;
3104 param.lastkeyid = cfg->remote_wake_ctrl_info.gtk_key_idx;
3105 _os_mem_cpy(hal_to_drvpriv(hal_info), param.ptktxiv, cfg->remote_wake_ctrl_info.ptk_tx_iv, IV_LENGTH);
3106 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxptkiv, cfg->remote_wake_ctrl_info.ptk_rx_iv, IV_LENGTH);
3107 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_0, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx0, IV_LENGTH);
3108 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_1, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx1, IV_LENGTH);
3109 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_2, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx2, IV_LENGTH);
3110 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_3, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx3, IV_LENGTH);
3111 content = ¶m;
3112 }
3113 }
3114
3115 /* should pass cfg->remote_wake_ctrl_info to halmac */
3116 if (hal_mac_ops->cfg_wow_wake(mac, (u8)macid, &info, content))
3117 return RTW_HAL_STATUS_FAILURE;
3118
3119 return RTW_HAL_STATUS_SUCCESS;
3120 }
3121
3122 enum rtw_hal_status
rtw_hal_mac_get_wake_rsn(struct hal_info_t * hal_info,u8 * wake_rsn,u8 * reset)3123 rtw_hal_mac_get_wake_rsn(struct hal_info_t *hal_info, u8 *wake_rsn, u8 *reset)
3124 {
3125 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3126 struct mac_ax_ops *hal_mac_ops = mac->ops;
3127
3128 if (hal_mac_ops->get_wow_wake_rsn(mac, wake_rsn, reset) != MACSUCCESS)
3129 return RTW_HAL_STATUS_FAILURE;
3130
3131 return RTW_HAL_STATUS_SUCCESS;
3132 }
3133
3134 enum rtw_hal_status
rtw_hal_mac_cfg_ndp_ofld(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_ndp_ofld_info * cfg)3135 rtw_hal_mac_cfg_ndp_ofld(struct hal_info_t *hal_info, u16 macid, u8 en, struct rtw_ndp_ofld_info *cfg)
3136 {
3137 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3138 struct mac_ax_ops *hal_mac_ops = mac->ops;
3139 struct mac_ax_ndp_ofld_info info = {0};
3140 struct mac_ax_ndp_info_parm_ content[2];
3141 void* drv_priv = hal_to_drvpriv(hal_info);
3142 u8 idx = 0;
3143
3144 if (en && cfg == NULL)
3145 return RTW_HAL_STATUS_FAILURE;
3146
3147 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_ndp_ofld_info));
3148 _os_mem_set(drv_priv, content, 0, sizeof(struct mac_ax_ndp_info_parm_)*2);
3149
3150 if (en) {
3151 info.ndp_en = cfg->ndp_en;
3152 info.na_id = cfg->ndp_id;
3153 for (idx = 0; idx < 2; idx++) {
3154 content[idx].enable = cfg->ndp_ofld_content[idx].ndp_en;
3155 _os_mem_cpy(drv_priv,content[idx].targetlinkaddress,
3156 cfg->ndp_ofld_content[idx].mac_addr, MAC_ADDRESS_LENGTH);
3157 content[idx].checkremoveip = cfg->ndp_ofld_content[idx].chk_remote_ip;
3158 _os_mem_cpy(drv_priv,content[idx].remoteipv6address,
3159 cfg->ndp_ofld_content[idx].remote_ipv6_addr, IPV6_ADDRESS_LENGTH);
3160 content[idx].numberoftargetip = cfg->ndp_ofld_content[0].num_target_ip;
3161 _os_mem_cpy(drv_priv,&(content[idx].targetip[0][0]),
3162 &(cfg->ndp_ofld_content[idx].target_ipv6_addr[0][0]), IPV6_ADDRESS_LENGTH*2);
3163 }
3164 }
3165
3166 if (hal_mac_ops->cfg_ndp_ofld(mac, (u8)macid, &info, content))
3167 return RTW_HAL_STATUS_FAILURE;
3168
3169 return RTW_HAL_STATUS_SUCCESS;
3170 }
3171
3172 enum rtw_hal_status
rtw_hal_mac_cfg_arp_ofld(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_arp_ofld_info * cfg)3173 rtw_hal_mac_cfg_arp_ofld(struct hal_info_t *hal_info, u16 macid, u8 en,
3174 struct rtw_arp_ofld_info *cfg)
3175 {
3176
3177 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3178 struct mac_ax_ops *hal_mac_ops = mac->ops;
3179 struct mac_ax_arp_ofld_info info = {0};
3180
3181 if (en && cfg == NULL)
3182 return RTW_HAL_STATUS_FAILURE;
3183
3184 if (en) {
3185 info.arp_en = cfg->arp_en;
3186 info.arp_rsp_id = cfg->arp_rsp_id;
3187 info.arp_action = cfg->arp_action;
3188 }
3189
3190 if (hal_mac_ops->cfg_arp_ofld(mac, (u8)macid, &info, NULL))
3191 return RTW_HAL_STATUS_FAILURE;
3192
3193 return RTW_HAL_STATUS_SUCCESS;
3194 }
3195
3196 enum rtw_hal_status
rtw_hal_mac_cfg_wow_cam(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_pattern_match_info * cfg)3197 rtw_hal_mac_cfg_wow_cam(struct hal_info_t *hal_info, u16 macid, u8 en,
3198 struct rtw_pattern_match_info *cfg)
3199 {
3200 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3201 struct mac_ax_ops *hal_mac_ops = mac->ops;
3202 struct rtw_wowcam_upd_info *wowcam_info = NULL;
3203 struct mac_ax_wowcam_upd_info info;
3204 void* drv_priv = hal_to_drvpriv(hal_info);
3205 u8 i = 0;
3206 u8 j = 0;
3207
3208 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s (en: %u) ==>\n", __func__, en);
3209
3210 if (en && cfg == NULL) {
3211 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for input cfg == NULL\n", __func__);
3212 return RTW_HAL_STATUS_FAILURE;
3213 }
3214
3215 /* config each wow cam, no matter valid or not */
3216 for (i = 0; i < MAX_WOW_CAM_NUM; ++i) {
3217 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_wowcam_upd_info));
3218
3219 if (en) {
3220 wowcam_info = &(cfg->wowcam_info[i]);
3221
3222 info.idx = wowcam_info->wow_cam_idx;
3223 info.r_w = wowcam_info->rw;
3224 info.valid = wowcam_info->valid;
3225
3226 if (wowcam_info->valid != 0) {
3227 info.wkfm1 = wowcam_info->wake_mask[0];
3228 info.wkfm2 = wowcam_info->wake_mask[1];
3229 info.wkfm3 = wowcam_info->wake_mask[2];
3230 info.wkfm4 = wowcam_info->wake_mask[3];
3231 info.crc = wowcam_info->match_crc;
3232 info.negative_pattern_match = wowcam_info->is_negative_pattern_match;
3233 info.skip_mac_hdr = wowcam_info->skip_mac_hdr;
3234 info.uc = wowcam_info->uc;
3235 info.mc = wowcam_info->mc;
3236 info.bc = wowcam_info->bc;
3237
3238 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "wow_cam [%u]:\n", info.idx);
3239
3240 for (j = 0; j < 4; ++j)
3241 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- wake_mask[%u] = 0x%08x\n", j, wowcam_info->wake_mask[j]);
3242 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rw, crc = (%u, 0x%08x)\n", info.r_w, info.crc);
3243 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- Neg_ptn_mtch = %u\n", info.negative_pattern_match);
3244 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- SkipMacHdr = %u\n", info.skip_mac_hdr);
3245 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- (UC, MC, BC) = (%u, %u, %u)\n", info.uc, info.mc, info.bc);
3246 } else {
3247 continue;
3248 }
3249 } else {
3250 info.idx = i;
3251 info.r_w = 1;
3252 info.valid = 0;
3253 }
3254
3255 if (hal_mac_ops->cfg_wowcam_upd(mac, &info)) {
3256 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for cfg wowcam(%u)\n", __func__, info.idx);
3257 return RTW_HAL_STATUS_FAILURE;
3258 }
3259 }
3260
3261 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s() <==\n", __func__);
3262
3263 return RTW_HAL_STATUS_SUCCESS;
3264 }
3265
_hal_mac_recv_aoac_report(struct mac_ax_adapter * mac,struct mac_ax_aoac_report * buf,u8 rx_rdy)3266 static u32 _hal_mac_recv_aoac_report(struct mac_ax_adapter *mac, struct mac_ax_aoac_report *buf, u8 rx_rdy)
3267 {
3268 struct mac_ax_ops *hal_mac_ops = mac->ops;
3269 u32 mac_status = 0;
3270
3271 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s(): request aoac report.\n", __func__);
3272
3273 mac_status = hal_mac_ops->request_aoac_report(mac, rx_rdy);
3274
3275 if (mac_status) {
3276 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== mac_status(%u) from request_aoac_report()\n", __func__, mac_status);
3277 return mac_status;
3278 }
3279
3280 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s(): read aoac report\n", __func__);
3281
3282 mac_status = hal_mac_ops->read_aoac_report(mac, buf, rx_rdy);
3283
3284 if (mac_status) {
3285 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== get mac_status(%u) from read_aoac_report()\n", __func__, mac_status);
3286 return mac_status;
3287 }
3288
3289 return mac_status;
3290 }
3291
3292 #define KEY_ID_MASK 0x3
3293 #define KEY_ID_OFFSET 6
3294
_hal_mac_aoac_rpt_chk(struct rtw_aoac_report * aoac_info)3295 enum rtw_hal_status _hal_mac_aoac_rpt_chk(struct rtw_aoac_report *aoac_info)
3296 {
3297 u8 key_id_from_iv = 0;
3298 u32 rx_iv = *((u32 *)aoac_info->ptk_rx_iv);
3299
3300 /* Case I. Aoac report is all zero in phase 0 */
3301 if (rx_iv == 0) {
3302 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): ptk_rx_iv is Zero, treating this case as error.\n", __func__);
3303 return RTW_HAL_STATUS_FAILURE;
3304 }
3305
3306 /* Case II. KEY_IDX does not match with GTK_RX_IV */
3307 key_id_from_iv = (aoac_info->gtk_rx_iv[aoac_info->key_idx][3] >> KEY_ID_OFFSET) & KEY_ID_MASK;
3308
3309 if (key_id_from_iv != aoac_info->key_idx) {
3310 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): Key_idx(%u) not match with the one(%u) parsed from GTK_RX_IV[%u]\n",
3311 __func__, aoac_info->key_idx, key_id_from_iv, aoac_info->key_idx);
3312 return RTW_HAL_STATUS_FAILURE;
3313 }
3314
3315 return RTW_HAL_STATUS_SUCCESS;
3316 }
3317
3318 /*
3319 AOAC_RPT - PHASE 0:
3320 Halmac will get aoac report through c2h reg.
3321
3322 (Cuz at this moment, the rx is still blocked by host.
3323 The rx cannot be resume only if those IV be updated by aoac_rpt)
3324
3325 In PHASE 0, Fw will transfer some necessary info,
3326 such as RX_IV, GTK_KEY_ID, GTK_RX_IV, Rekey_OK and iGTK_ipn.
3327 */
3328
3329 enum rtw_hal_status
_hal_mac_read_aoac_rpt_phase_0(void * drv_priv,struct mac_ax_aoac_report * aoac_rpt_buf,struct rtw_aoac_report * aoac_info)3330 _hal_mac_read_aoac_rpt_phase_0(void* drv_priv, struct mac_ax_aoac_report *aoac_rpt_buf, struct rtw_aoac_report *aoac_info)
3331 {
3332 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
3333
3334 aoac_info->rekey_ok = aoac_rpt_buf->rekey_ok;
3335 aoac_info->key_idx = aoac_rpt_buf->key_idx;
3336 _os_mem_cpy(drv_priv, aoac_info->ptk_rx_iv, aoac_rpt_buf->ptk_rx_iv, IV_LENGTH);
3337
3338 switch (aoac_info->key_idx) {
3339 case 0:
3340 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[0], aoac_rpt_buf->gtk_rx_iv_0, IV_LENGTH);
3341 break;
3342 case 1:
3343 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[1], aoac_rpt_buf->gtk_rx_iv_1, IV_LENGTH);
3344 break;
3345 case 2:
3346 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[2], aoac_rpt_buf->gtk_rx_iv_2, IV_LENGTH);
3347 break;
3348 case 3:
3349 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[3], aoac_rpt_buf->gtk_rx_iv_3, IV_LENGTH);
3350 break;
3351 default:
3352 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): Unknown gtk_key_idx(%u)\n", __func__, aoac_info->key_idx);
3353 break;
3354 }
3355
3356 if (aoac_info->rekey_ok)
3357 _os_mem_cpy(drv_priv, aoac_info->igtk_ipn, aoac_rpt_buf->igtk_ipn, sizeof(aoac_rpt_buf->igtk_ipn));
3358
3359 hal_status = _hal_mac_aoac_rpt_chk(aoac_info);
3360
3361 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "PHASE 0:\n");
3362
3363 debug_dump_data((u8 *)aoac_rpt_buf, sizeof(struct mac_ax_aoac_report), "aoac_report");
3364
3365 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rekey_ok = %u\n", aoac_info->rekey_ok);
3366 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- key_idx = %u\n", aoac_info->key_idx);
3367 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- ptk_rx_iv = 0x%08x%08x\n", *((u32*)(aoac_info->ptk_rx_iv)+1), *((u32*)(aoac_info->ptk_rx_iv)));
3368 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- gtk_rx_iv[%u] = 0x%08x%08x\n",
3369 aoac_info->key_idx,
3370 *((u32*)(aoac_info->gtk_rx_iv[aoac_info->key_idx])+1),
3371 *((u32*)(aoac_info->gtk_rx_iv[aoac_info->key_idx])));
3372
3373 if (aoac_info->rekey_ok)
3374 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- igtk_ipn = 0x%08x%08x\n", *((u32*)(aoac_info->igtk_ipn)+1), *((u32*)(aoac_info->igtk_ipn)));
3375
3376 return hal_status;
3377 }
3378
3379 /*
3380 AOAC_RPT - PHASE 1:
3381 Halmac will get aoac report through c2h pkt.
3382
3383 (Cuz at this moment,
3384 the host has resumed the rx, c2h pkt can be used here.)
3385
3386 In PHASE 1, Fw will transfer all info in aoac report.
3387 Those entries got in phase 0 should remain the same value in phase 1.
3388 */
3389
3390 enum rtw_hal_status
_hal_mac_read_aoac_rpt_phase_1(void * drv_priv,struct mac_ax_aoac_report * aoac_rpt_buf,struct rtw_aoac_report * aoac_info)3391 _hal_mac_read_aoac_rpt_phase_1(void* drv_priv, struct mac_ax_aoac_report *aoac_rpt_buf, struct rtw_aoac_report *aoac_info)
3392 {
3393 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
3394 u8 i = 0;
3395
3396 aoac_info->rpt_ver = aoac_rpt_buf->rpt_ver;
3397 aoac_info->sec_type = aoac_rpt_buf->sec_type;
3398 aoac_info->pattern_idx = aoac_rpt_buf->pattern_idx;
3399
3400 _os_mem_cpy(drv_priv, aoac_info->ptk_tx_iv, aoac_rpt_buf->ptk_tx_iv, IV_LENGTH);
3401
3402 for (i = 0; i < 4; ++i) {
3403 switch (i) {
3404 case 0:
3405 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[0], aoac_rpt_buf->gtk_rx_iv_0, IV_LENGTH);
3406 break;
3407 case 1:
3408 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[1], aoac_rpt_buf->gtk_rx_iv_1, IV_LENGTH);
3409 break;
3410 case 2:
3411 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[2], aoac_rpt_buf->gtk_rx_iv_2, IV_LENGTH);
3412 break;
3413 case 3:
3414 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[3], aoac_rpt_buf->gtk_rx_iv_3, IV_LENGTH);
3415 break;
3416 default:
3417 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): Unknown gtk_key_idx(%u)\n", __func__, aoac_info->key_idx);
3418 break;
3419 }
3420 }
3421
3422 _os_mem_cpy(drv_priv, aoac_info->gtk, aoac_rpt_buf->gtk, sizeof(aoac_rpt_buf->gtk));
3423 _os_mem_cpy(drv_priv, aoac_info->eapol_key_replay_count, aoac_rpt_buf->eapol_key_replay_count, sizeof(aoac_rpt_buf->eapol_key_replay_count));
3424 _os_mem_cpy(drv_priv, aoac_info->igtk_key_id, aoac_rpt_buf->igtk_key_id, sizeof(aoac_rpt_buf->igtk_key_id));
3425 _os_mem_cpy(drv_priv, aoac_info->igtk, aoac_rpt_buf->igtk, sizeof(aoac_rpt_buf->igtk));
3426
3427 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "PHASE 1:\n");
3428
3429 debug_dump_data((u8 *)aoac_rpt_buf, sizeof(struct mac_ax_aoac_report), "aoac_report");
3430
3431 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rekey_ok = %u\n", aoac_info->rekey_ok);
3432 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- key_idx = %u\n", aoac_info->key_idx);
3433 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- ptk_rx_iv = 0x%08x%08x\n", *((u32*)(aoac_info->ptk_rx_iv)+1), *((u32*)(aoac_info->ptk_rx_iv)));
3434 for(i = 0; i < 4; ++i) {
3435 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- gtk_rx_iv[%u] = 0x%08x%08x\n",
3436 i,
3437 *((u32*)(aoac_info->gtk_rx_iv[i])+1),
3438 *((u32*)(aoac_info->gtk_rx_iv[i])));
3439 }
3440 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- ptk_tx_iv = 0x%08x%08x\n", *((u32*)(aoac_info->ptk_tx_iv)+1), *((u32*)(aoac_info->ptk_tx_iv)));
3441 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rpt_ver = %u\n", aoac_info->rpt_ver);
3442 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- sec_type = %u\n", aoac_info->sec_type);
3443 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- pattern_idx = %u\n", aoac_info->pattern_idx);
3444 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- eapol_key_replay_cnt = 0x%08x%08x\n", *((u32*)(aoac_info->eapol_key_replay_count)+1), *((u32*)(aoac_info->eapol_key_replay_count)));
3445 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- igtk_key_id = 0x%08x%08x\n", *((u32*)(aoac_info->igtk_key_id)+1), *((u32*)(aoac_info->igtk_key_id)));
3446 debug_dump_data(aoac_info->gtk, sizeof(aoac_rpt_buf->gtk), "GTK:");
3447 debug_dump_data(aoac_info->igtk, sizeof(aoac_rpt_buf->igtk), "iGTK:");
3448
3449 return hal_status;
3450 }
3451
3452 enum rtw_hal_status
rtw_hal_mac_get_aoac_rpt(struct hal_info_t * hal_info,struct rtw_aoac_report * aoac_info,u8 rx_ready)3453 rtw_hal_mac_get_aoac_rpt(struct hal_info_t *hal_info, struct rtw_aoac_report *aoac_info, u8 rx_ready)
3454 {
3455 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
3456 #ifndef RTW_WKARD_WOW_SKIP_AOAC_RPT
3457 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3458 #endif
3459 struct mac_ax_aoac_report aoac_rpt_buf;
3460 void* drv_priv = hal_to_drvpriv(hal_info);
3461 u32 mac_status = 0;
3462
3463 if (aoac_info == NULL) {
3464 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for input info == NULL\n", __func__);
3465 return RTW_HAL_STATUS_FAILURE;
3466 }
3467
3468 #ifdef RTW_WKARD_WOW_SKIP_AOAC_RPT
3469 mac_status = MACPROCERR;
3470 #else
3471 mac_status = _hal_mac_recv_aoac_report(mac, &aoac_rpt_buf, rx_ready);
3472 #endif
3473
3474 if (mac_status) {
3475 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for _hal_mac_recv_aoac_report fail with mac_status(%u).\n",
3476 __func__, mac_status);
3477 hal_status = RTW_HAL_STATUS_FAILURE;
3478 } else {
3479 if (rx_ready == 0)
3480 hal_status = _hal_mac_read_aoac_rpt_phase_0(drv_priv, &aoac_rpt_buf, aoac_info);
3481 else
3482 hal_status = _hal_mac_read_aoac_rpt_phase_1(drv_priv, &aoac_rpt_buf, aoac_info);
3483 }
3484
3485 return hal_status;
3486 }
3487
3488 enum rtw_hal_status
rtw_hal_mac_cfg_gtk_ofld(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_gtk_ofld_info * cfg)3489 rtw_hal_mac_cfg_gtk_ofld(struct hal_info_t *hal_info, u16 macid, u8 en,
3490 struct rtw_gtk_ofld_info *cfg)
3491 {
3492 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3493 struct mac_ax_ops *hal_mac_ops = mac->ops;
3494 struct mac_ax_gtk_ofld_info info;
3495 struct mac_ax_gtk_info_parm_ param;
3496 void* drv_priv = hal_to_drvpriv(hal_info);
3497
3498 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_gtk_ofld_info));
3499 _os_mem_set(drv_priv, ¶m, 0, sizeof(struct mac_ax_gtk_info_parm_));
3500
3501 if (en && cfg == NULL) {
3502 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for input cfg == NULL\n", __func__);
3503 return RTW_HAL_STATUS_FAILURE;
3504 }
3505
3506 if (en) {
3507 info.gtk_en = cfg->gtk_en;
3508 info.tkip_en = cfg->tkip_en;
3509 info.ieee80211w_en = cfg->ieee80211w_en;
3510 info.pairwise_wakeup = cfg->pairwise_wakeup;
3511 info.gtk_rsp_id = cfg->gtk_rsp_id;
3512
3513 info.algo_akm_suit = cfg->akmtype_byte3;
3514
3515 if (info.gtk_en) {
3516 _os_mem_cpy(drv_priv, param.kck, cfg->gtk_ofld_content.kck, cfg->gtk_ofld_content.kck_len);
3517 _os_mem_cpy(drv_priv, param.kek, cfg->gtk_ofld_content.kek, cfg->gtk_ofld_content.kek_len);
3518
3519 if (info.tkip_en)
3520 _os_mem_cpy(drv_priv, param.rxmickey, cfg->gtk_ofld_content.rxmickey, TKIP_MIC_KEY_LENGTH);
3521 }
3522
3523 if (info.ieee80211w_en) {
3524 info.bip_sec_algo = cfg->bip_sec_algo;
3525 info.pmf_sa_query_id = cfg->sa_query_id;
3526
3527 _os_mem_cpy(drv_priv, param.igtk_keyid, cfg->gtk_ofld_content.igtk_keyid, cfg->gtk_ofld_content.igtk_len);
3528 _os_mem_cpy(drv_priv, param.ipn, cfg->gtk_ofld_content.ipn, IGTK_PKT_NUM_LENGTH);
3529 _os_mem_cpy(drv_priv, param.igtk, &(cfg->gtk_ofld_content.igtk[0]), cfg->gtk_ofld_content.igtk_len);
3530
3531 if (cfg->hw_11w_en == 0)
3532 _os_mem_cpy(drv_priv, param.sk, cfg->gtk_ofld_content.psk, cfg->gtk_ofld_content.psk_len);
3533 }
3534 } else {
3535 info.gtk_en = false;
3536 info.ieee80211w_en = false;
3537 }
3538
3539 if (hal_mac_ops->cfg_gtk_ofld(mac, (u8)macid, &info, ¶m))
3540 return RTW_HAL_STATUS_FAILURE;
3541
3542 return RTW_HAL_STATUS_SUCCESS;
3543
3544 }
3545
3546 enum rtw_hal_status
rtw_hal_mac_cfg_realwow(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_realwow_info * cfg)3547 rtw_hal_mac_cfg_realwow(struct hal_info_t *hal_info, u16 macid, u8 en,
3548 struct rtw_realwow_info *cfg)
3549 {
3550 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3551 struct mac_ax_ops *hal_mac_ops = mac->ops;
3552 struct mac_ax_realwow_info info = {0};
3553 struct mac_ax_realwowv2_info_parm_ param = {0};
3554 void *drv_priv = hal_to_drvpriv(hal_info);
3555
3556 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_realwow_info));
3557 _os_mem_set(drv_priv, ¶m, 0, sizeof(struct mac_ax_realwowv2_info_parm_));
3558
3559 if (en) {
3560 info.realwow_en = cfg->realwow_en;
3561 info.auto_wakeup = cfg->auto_wakeup;
3562 info.keepalive_id = cfg->keepalive_id;
3563 info.wakeup_pattern_id = cfg->wakeup_pattern_id;
3564 info.ack_pattern_id = cfg->ack_pattern_id;
3565 if (info.realwow_en) {
3566 param.interval = cfg->realwow_ofld_content.interval;
3567 param.kapktsize = cfg->realwow_ofld_content.keep_alive_pkt_size;
3568 param.acklostlimit = cfg->realwow_ofld_content.ack_lost_limit;
3569 param.ackpatternsize = cfg->realwow_ofld_content.ack_ptrn_size;
3570 param.wakeuppatternsize = cfg->realwow_ofld_content.wakeup_ptrn_size;
3571 param.wakeupsecnum = cfg->realwow_ofld_content.wakeup_sec_num;
3572 }
3573 } else {
3574 info.realwow_en = false;
3575 }
3576
3577 if (hal_mac_ops->cfg_realwow(mac, (u8)macid, &info, ¶m))
3578 return RTW_HAL_STATUS_FAILURE;
3579
3580 return RTW_HAL_STATUS_SUCCESS;
3581 }
3582
rtw_hal_mac_set_wowlan(struct hal_info_t * hal,u8 enter)3583 enum rtw_hal_status rtw_hal_mac_set_wowlan(struct hal_info_t *hal, u8 enter)
3584 {
3585 u32 mac_err = 0;
3586 struct mac_ax_adapter *mac = hal_to_mac(hal);
3587 enum mac_ax_wow_ctrl ctrl = (enter == 1) ? MAC_AX_WOW_ENTER : MAC_AX_WOW_LEAVE;
3588
3589 mac_err = mac->ops->intf_ops->set_wowlan(mac, ctrl);
3590 if (mac_err != MACSUCCESS)
3591 return RTW_HAL_STATUS_FAILURE;
3592
3593 return RTW_HAL_STATUS_SUCCESS;
3594 }
3595
_wow_is_txq_empty(struct mac_ax_tx_queue_empty * val)3596 static bool _wow_is_txq_empty(struct mac_ax_tx_queue_empty *val)
3597 {
3598 u8 i = 0;
3599 u8 size = ARRAY_SIZE(val->macid_txq_empty);
3600
3601 if (!val->others_empty)
3602 return false;
3603
3604 if (!val->band0_mgnt_empty)
3605 return false;
3606
3607 if (!val->band1_mgnt_empty)
3608 return false;
3609
3610 for (i = 0; i < size; i++) {
3611 if (val->macid_txq_empty[i] != 0xFF)
3612 return false;
3613 }
3614
3615 PHL_INFO("%s : others_empty %d.\n", __func__, val->others_empty);
3616 PHL_INFO("%s : band0_mgnt_empty %d.\n", __func__, val->band0_mgnt_empty);
3617 PHL_INFO("%s : band1_mgnt_empty %d.\n", __func__, val->band1_mgnt_empty);
3618 for (i = 0; i < size; i++)
3619 PHL_INFO("%s : macid_txq_empty[%d] %d.\n", __func__, i, val->macid_txq_empty[i]);
3620
3621 return true;
3622 }
3623
3624 #define MAX_WOW_POLLNG_TXQ_EMPTY_TIME 50000 /* us */
3625 #define MAX_WOW_CHK_TXQ_EMPTY_CNT 2 /* continously check ok should satisfied this value */
rtw_hal_mac_wow_chk_txq_empty(struct hal_info_t * hal,u8 * empty)3626 enum rtw_hal_status rtw_hal_mac_wow_chk_txq_empty(struct hal_info_t *hal, u8 *empty)
3627 {
3628 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
3629 struct mac_ax_adapter *mac = hal_to_mac(hal);
3630 struct mac_ax_tx_queue_empty val = {0};
3631 u32 start_t = _os_get_cur_time_us();
3632 u8 chk_cnt = 0;
3633
3634 while (1) {
3635
3636 if (phl_get_passing_time_us(start_t) >= MAX_WOW_POLLNG_TXQ_EMPTY_TIME) {
3637 PHL_ERR("%s : reach maximum polling time.\n", __func__);
3638 break;
3639 }
3640
3641 for (chk_cnt = 0; chk_cnt < MAX_WOW_CHK_TXQ_EMPTY_CNT; chk_cnt++) {
3642 if (mac->ops->is_txq_empty(mac, &val) != MACSUCCESS)
3643 break;
3644
3645 if (!_wow_is_txq_empty(&val)) {
3646 break;
3647 } else {
3648 *empty = 1;
3649 }
3650 }
3651
3652 if (*empty)
3653 break;
3654
3655 _os_delay_us(hal_to_drvpriv(hal), 50);
3656 }
3657
3658 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s : polling empty %d with duration %d.\n",
3659 __func__, *empty, phl_get_passing_time_us(start_t));
3660
3661 return hstatus;
3662 }
3663
rtw_hal_mac_wow_wde_drop(struct hal_info_t * hal,u8 band)3664 enum rtw_hal_status rtw_hal_mac_wow_wde_drop(struct hal_info_t *hal, u8 band)
3665 {
3666 struct mac_ax_adapter *mac = hal_to_mac(hal);
3667 struct mac_ax_pkt_drop_info info = {0};
3668 u32 mac_err = 0;
3669
3670 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s with band %d.\n", __func__, band);
3671
3672 info.sel = MAC_AX_PKT_DROP_SEL_BAND_ONCE;
3673 info.band = band;
3674
3675 mac_err = mac->ops->pkt_drop(mac, &info);
3676 if (mac_err != MACSUCCESS)
3677 return RTW_HAL_STATUS_FAILURE;
3678
3679 return RTW_HAL_STATUS_SUCCESS;
3680 }
3681
3682 enum rtw_hal_status
rtw_hal_mac_scan_ofld(struct hal_info_t * hal,u16 mac_id,u8 hw_band,u8 hw_port,struct scan_ofld_info * cfg)3683 rtw_hal_mac_scan_ofld(struct hal_info_t *hal, u16 mac_id, u8 hw_band, u8 hw_port,
3684 struct scan_ofld_info *cfg)
3685 {
3686 struct mac_ax_adapter *mac = hal_to_mac(hal);
3687 struct mac_ax_scanofld_param param = {0};
3688 u32 mac_err = 0;
3689
3690 param.macid = mac_id;
3691 param.port_id = hw_port;
3692 param.band = hw_band;
3693 param.operation = cfg->operation;
3694 param.probe_req_pkt_id = cfg->probe_req_pkt_id;
3695 param.tsf_low = cfg->tsf_low;
3696 param.tsf_high = cfg->tsf_high;
3697 param.scan_type = cfg->mode;
3698 param.norm_pd = cfg->period;
3699 param.norm_cy = cfg->cycle;
3700 param.slow_pd = cfg->slow_period;
3701
3702 if (cfg->tsf_high != 0 || cfg->tsf_low != 0)
3703 param.start_mode = 1;
3704
3705 PHL_INFO("%s : macid/port/band/operation/pkt_id/tsf_low/tsf_high =\
3706 %u/%u/%u/%u/%u/%u/%u \n", __func__,
3707 param.macid, param.port_id, param.band, param.operation,
3708 param.probe_req_pkt_id, param.tsf_low, param.tsf_high);
3709
3710 PHL_INFO("%s : scan_type/norm_pd/norm_cy/slow_pd =\
3711 %u/%u/%u/%u \n", __func__,
3712 param.scan_type, param.norm_pd, param.norm_cy, param.slow_pd);
3713
3714 mac_err = mac->ops->scanofld(mac, ¶m);
3715
3716 if (MACSUCCESS != mac_err) {
3717 PHL_ERR("%s : failed, mac error = %u \n", __func__, mac_err);
3718 return RTW_HAL_STATUS_FAILURE;
3719 }
3720
3721 return RTW_HAL_STATUS_SUCCESS;
3722
3723 }
3724
3725 enum rtw_hal_status
rtw_hal_mac_scan_ofld_chlist_busy(struct hal_info_t * hal)3726 rtw_hal_mac_scan_ofld_chlist_busy(struct hal_info_t *hal)
3727 {
3728 struct mac_ax_adapter *mac = hal_to_mac(hal);
3729
3730 if (mac->ops->scanofld_chlist_busy(mac))
3731 return RTW_HAL_STATUS_FAILURE;
3732
3733 return RTW_HAL_STATUS_SUCCESS;
3734 }
3735
3736 #define MAX_POLLING_FW_STS_TIME 100 /* ms */
3737 enum rtw_hal_status
rtw_hal_mac_scan_ofld_add_ch(struct hal_info_t * hal,struct scan_ofld_ch_info * cfg,bool ofld)3738 rtw_hal_mac_scan_ofld_add_ch(struct hal_info_t *hal,
3739 struct scan_ofld_ch_info *cfg, bool ofld)
3740 {
3741 struct mac_ax_adapter *mac = hal_to_mac(hal);
3742 struct mac_ax_scanofld_chinfo chinfo = {0};
3743 u32 mac_err = 0, poll_cnt = 0, cur_time = _os_get_cur_time_ms();
3744 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
3745 void *drv_priv = hal_to_drvpriv(hal);
3746
3747 chinfo.central_ch = cfg->center_chan;
3748 chinfo.pri_ch = cfg->chan;
3749 chinfo.bw = cfg->bw;
3750 chinfo.period = cfg->period;
3751 chinfo.tx_pkt = cfg->tx_pkt;
3752 chinfo.pause_tx_data = cfg->tx_data_pause;
3753
3754 PHL_INFO("%s : central_ch/pri_ch/bw/period/tx_pkt/pause_tx_data =\
3755 %u/%u/%u/%u/%u/%u \n", __func__,
3756 chinfo.central_ch, chinfo.pri_ch, chinfo.bw, chinfo.period,
3757 chinfo.tx_pkt, chinfo.pause_tx_data);
3758
3759 mac_err = mac->ops->add_scanofld_ch(mac, &chinfo, ofld, true);
3760
3761 if (MACSUCCESS != mac_err) {
3762 PHL_ERR("%s : failed, mac error = %u \n", __func__, mac_err);
3763 return RTW_HAL_STATUS_FAILURE;
3764 }
3765
3766 if (ofld == false)
3767 return RTW_HAL_STATUS_SUCCESS;
3768
3769 /* polling fw status */
3770 while (1) {
3771
3772 if (phl_get_passing_time_ms(cur_time) > MAX_POLLING_FW_STS_TIME) {
3773 PHL_ERR("%s polling fw status timeout !!!\n", __func__);
3774 hstatus = RTW_HAL_STATUS_FAILURE;
3775 break;
3776 }
3777
3778 if (mac->ops->scanofld_chlist_busy(mac)) {
3779 _os_delay_ms(drv_priv, 1);
3780 } else {
3781 PHL_INFO("%s : passing time %ums\n", __func__,
3782 phl_get_passing_time_ms(cur_time));
3783 break;
3784 }
3785
3786 poll_cnt++;
3787 }
3788
3789 return RTW_HAL_STATUS_SUCCESS;
3790 }
3791
3792 enum rtw_hal_status
rtw_hal_mac_scan_ofld_fw_busy(struct hal_info_t * hal)3793 rtw_hal_mac_scan_ofld_fw_busy(struct hal_info_t *hal)
3794 {
3795 struct mac_ax_adapter *mac = hal_to_mac(hal);
3796
3797 if (mac->ops->scanofld_fw_busy(mac))
3798 return RTW_HAL_STATUS_FAILURE;
3799
3800 return RTW_HAL_STATUS_SUCCESS;
3801 }
3802
3803 enum rtw_hal_status
rtw_hal_mac_cfg_nlo(struct hal_info_t * hal,u16 macid,u8 en,struct rtw_nlo_info * cfg)3804 rtw_hal_mac_cfg_nlo(struct hal_info_t *hal, u16 macid, u8 en,
3805 struct rtw_nlo_info *cfg)
3806 {
3807 struct mac_ax_adapter *mac = hal_to_mac(hal);
3808 struct mac_ax_nlo_info info = {0};
3809 struct mac_ax_nlo_networklist_parm_ content = {0};
3810 void *d = hal_to_drvpriv(hal);
3811 u8 i = 0;
3812 u32 mac_err;
3813
3814 info.nlo_en = en;
3815
3816 if (en) {
3817 content.numofentries = cfg->num_of_networks;
3818 _os_mem_cpy(d, content.ssidlen, cfg->ssidlen, content.numofentries);
3819 _os_mem_cpy(d, content.ssid, cfg->ssid,
3820 content.numofentries* MAX_SSID_LEN);
3821 _os_mem_cpy(d, content.chipertype, cfg->chipertype,
3822 content.numofentries);
3823
3824 PHL_INFO("%s : num of ssid %u \n", __func__, content.numofentries);
3825
3826 for (i = 0; i < content.numofentries; i++) {
3827 PHL_INFO("%s : #%u ssid/len = %s/%u \n", __func__, i+1,
3828 (char *)content.ssid[i], content.ssidlen[i]);
3829 }
3830 }
3831
3832 mac_err = mac->ops->cfg_nlo(mac, (u8)macid, &info, &content);
3833
3834 if (MACSUCCESS != mac_err) {
3835 PHL_ERR("%s : failed, mac err (%u) \n", __func__, mac_err);
3836 return RTW_HAL_STATUS_FAILURE;
3837 }
3838
3839 return RTW_HAL_STATUS_SUCCESS;
3840 }
3841
3842 #endif /* CONFIG_WOWLAN */
3843
3844 static enum rtw_hal_status
hal_mac_read_efuse(struct mac_ax_adapter * mac,u32 addr,u32 size,u8 * val,enum mac_ax_efuse_bank bank)3845 hal_mac_read_efuse(struct mac_ax_adapter *mac, u32 addr, u32 size,
3846 u8 *val, enum mac_ax_efuse_bank bank)
3847 {
3848 if (mac->ops->read_efuse(mac, addr, size, val, bank) != MACSUCCESS)
3849 return RTW_HAL_STATUS_FAILURE;
3850 return RTW_HAL_STATUS_SUCCESS;
3851 }
3852
3853 static enum rtw_hal_status
hal_mac_write_efuse(struct mac_ax_adapter * mac,u32 addr,u8 val,enum mac_ax_efuse_bank bank)3854 hal_mac_write_efuse(struct mac_ax_adapter *mac, u32 addr, u8 val,
3855 enum mac_ax_efuse_bank bank)
3856 {
3857 if (mac->ops->write_efuse(mac, addr, val, bank) != MACSUCCESS)
3858 return RTW_HAL_STATUS_FAILURE;
3859 return RTW_HAL_STATUS_SUCCESS;
3860 }
3861
3862 enum rtw_hal_status
rtw_hal_mac_enable_cpu(struct hal_info_t * hal_info,u8 reason,u8 dlfw)3863 rtw_hal_mac_enable_cpu(struct hal_info_t *hal_info, u8 reason, u8 dlfw)
3864 {
3865 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3866
3867 if (mac->ops->enable_cpu(mac, reason, dlfw) != MACSUCCESS)
3868 return RTW_HAL_STATUS_FAILURE;
3869 return RTW_HAL_STATUS_SUCCESS;
3870 }
3871
3872 enum rtw_hal_status
rtw_hal_mac_disable_cpu(struct hal_info_t * hal_info)3873 rtw_hal_mac_disable_cpu(struct hal_info_t *hal_info)
3874 {
3875 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3876
3877 if (mac->ops->disable_cpu(mac) != MACSUCCESS)
3878 return RTW_HAL_STATUS_FAILURE;
3879 return RTW_HAL_STATUS_SUCCESS;
3880 }
3881
3882 enum rtw_hal_status
rtw_hal_mac_romdl(struct hal_info_t * hal_info,u8 * rom_buf,u32 rom_size)3883 rtw_hal_mac_romdl(struct hal_info_t *hal_info, u8 *rom_buf, u32 rom_size)
3884 {
3885 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3886 u32 rom_addr = 0x18900000;
3887
3888 if (mac->ops->romdl(mac, rom_buf, rom_addr, rom_size) != MACSUCCESS)
3889 return RTW_HAL_STATUS_FAILURE;
3890 return RTW_HAL_STATUS_SUCCESS;
3891 }
3892
3893 enum rtw_hal_status
rtw_hal_mac_fwdl(struct hal_info_t * hal_info,u8 * fw_buf,u32 fw_size)3894 rtw_hal_mac_fwdl(struct hal_info_t *hal_info, u8 *fw_buf, u32 fw_size)
3895 {
3896 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3897 u32 mac_err;
3898
3899 mac_err = mac->ops->fwdl(mac, fw_buf, fw_size);
3900 if (mac_err != MACSUCCESS) {
3901 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
3902 return RTW_HAL_STATUS_FAILURE;
3903 }
3904
3905 hal_mac_print_fw_version(hal_info);
3906
3907 return RTW_HAL_STATUS_SUCCESS;
3908 }
3909
3910 enum rtw_hal_status
rtw_hal_mac_enable_fw(struct hal_info_t * hal_info,u8 fw_type)3911 rtw_hal_mac_enable_fw(struct hal_info_t *hal_info, u8 fw_type)
3912 {
3913 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3914 u32 mac_err;
3915
3916 mac_err = mac->ops->enable_fw(mac, fw_type);
3917 if (mac_err != MACSUCCESS) {
3918 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
3919 return RTW_HAL_STATUS_FAILURE;
3920 }
3921
3922 hal_mac_print_fw_version(hal_info);
3923 return RTW_HAL_STATUS_SUCCESS;
3924 }
3925
3926 /* */
3927 /**
3928 * rtw_hal_mac_ax_fill_txdesc
3929 * @mac: see struct mac_ax_adapter
3930 * @treq: the xmit request for this tx descriptor
3931 * @wd_buf: the wd buffer to fill
3932 * @wd_len: output, return the total length of filled wd
3933 *
3934 * Note,halmac API for hal and proto type is at hal_api_mac.h
3935 */
3936 enum rtw_hal_status
rtw_hal_mac_ax_fill_txdesc(void * mac,struct rtw_xmit_req * treq,u8 * wd_buf,u32 * wd_len)3937 rtw_hal_mac_ax_fill_txdesc(void *mac, struct rtw_xmit_req *treq,
3938 u8 *wd_buf, u32 *wd_len)
3939 {
3940 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
3941 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
3942
3943 *wd_len = mac_info->ops->txdesc_len(
3944 mac_info,
3945 &treq->mdata);
3946
3947 hal_status = mac_info->ops->build_txdesc(
3948 mac_info,
3949 &treq->mdata, wd_buf, *wd_len);
3950
3951
3952 return hal_status;
3953 }
3954
3955 /**
3956 * rtw_hal_mac_set_hw_ampdu_cfg
3957 * @hal_info: see struct hal_info_t
3958 * @band: target band this AMPDU going to send
3959 * @max_agg_num: AMPDU maximum aggregation number
3960 * @max_agg_time: AMPDU maximum aggregation time, in unit of 32 us
3961 *
3962 * Note,
3963 * (1) halmac API for hal and proto type is at hal_api_mac.h
3964 */
3965 enum rtw_hal_status
rtw_hal_mac_set_hw_ampdu_cfg(struct hal_info_t * hal_info,u8 band,u16 max_agg_num,u8 max_agg_time)3966 rtw_hal_mac_set_hw_ampdu_cfg(struct hal_info_t *hal_info,
3967 u8 band,
3968 u16 max_agg_num, u8 max_agg_time)
3969 {
3970 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
3971 struct mac_ax_ampdu_cfg info;
3972 u32 mac_err;
3973
3974 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3975
3976 info.band = band;
3977 info.wdbk_mode = MAC_AX_WDBK_MODE_SINGLE_BK;
3978 info.rty_bk_mode = MAC_AX_RTY_BK_MODE_AGG;
3979 info.max_agg_num = max_agg_num;
3980 info.max_agg_time_32us = max_agg_time;
3981
3982 mac_err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_AMPDU_CFG, &info);
3983
3984 if (mac_err != MACSUCCESS)
3985 goto fail;
3986
3987 return RTW_HAL_STATUS_SUCCESS;
3988 fail:
3989 return RTW_HAL_STATUS_MAC_API_FAILURE;
3990 }
3991
3992
3993 /**
3994 * the function to update DMAC control info by halmac api
3995 * @hal_info: see struct hal_info_t
3996 * @dctl_info: structure of dmac control information, define by halmac
3997 * @macid: the macid corresponding to this cmac control info
3998 *
3999 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4000 */
rtw_hal_dmc_tbl_cfg(struct hal_info_t * hal_info,struct mac_ax_dctl_info * dctl_info,struct mac_ax_dctl_info * dctl_info_mask,u16 macid)4001 enum rtw_hal_status rtw_hal_dmc_tbl_cfg(struct hal_info_t *hal_info,
4002 struct mac_ax_dctl_info *dctl_info,
4003 struct mac_ax_dctl_info *dctl_info_mask,
4004 u16 macid)
4005 {
4006 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4007 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4008 u32 ret = 0;
4009
4010 ret = mac->ops->upd_dctl_info(mac, dctl_info, dctl_info_mask, (u8)macid, 1);
4011
4012 if (0 == ret) {
4013 sts = RTW_HAL_STATUS_SUCCESS;
4014 } else {
4015 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "mac_upd_dctl_info fail (0x%08X)\n",
4016 ret);
4017 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4018 }
4019
4020 return sts;
4021 }
4022
4023
4024
4025 /**
4026 * the function to update CMAC control info by halmac api
4027 * @hal_info: see struct hal_info_t
4028 * @cctl_info: structure of cmac control information, define by halmac
4029 * @macid: the macid corresponding to this cmac control info
4030 *
4031 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4032 */
rtw_hal_cmc_tbl_cfg(struct hal_info_t * hal_info,struct rtw_hal_mac_ax_cctl_info * cctl_info,struct rtw_hal_mac_ax_cctl_info * cctl_info_mask,u16 macid)4033 enum rtw_hal_status rtw_hal_cmc_tbl_cfg(struct hal_info_t *hal_info,
4034 struct rtw_hal_mac_ax_cctl_info *cctl_info,
4035 struct rtw_hal_mac_ax_cctl_info *cctl_info_mask,
4036 u16 macid)
4037 {
4038 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4039 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4040 u32 ret = 0;
4041 cctl_info_mask->addr_cam_index = 0;
4042
4043 ret = mac->ops->upd_cctl_info(mac, cctl_info, cctl_info_mask, (u8)macid, 1);
4044
4045 if (0 == ret) {
4046 sts = RTW_HAL_STATUS_SUCCESS;
4047 } else {
4048 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "mac_upd_cctl_info fail (0x%08X)\n",
4049 ret);
4050 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4051 }
4052
4053 return sts;
4054 }
4055
4056
4057 /**
4058 * the function to update BA CAM entry by halmac api
4059 * @hal_info: see struct hal_info_t
4060 * @ba_cam: structure of ba cam entry, define by halmac
4061 *
4062 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4063 */
rtw_hal_bacam_cfg(struct hal_info_t * hal_info,struct mac_ax_bacam_info * ba_cam)4064 enum rtw_hal_status rtw_hal_bacam_cfg(struct hal_info_t *hal_info,
4065 struct mac_ax_bacam_info *ba_cam)
4066 {
4067 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4068 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4069 u32 ret = 0;
4070
4071 ret = mac->ops->bacam_info(mac, ba_cam);
4072
4073 if (0 == ret) {
4074 sts = RTW_HAL_STATUS_SUCCESS;
4075 } else {
4076 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "mac_bacam_info fail (0x%08X)\n",
4077 ret);
4078 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4079 }
4080
4081 return sts;
4082 }
4083
4084 /**
4085 * rtw_hal_mac_set_bw() - Update channel and bandwdith related setting
4086 * @hal_info: struct hal_info_t*
4087 * @band_idx: 0x0: band0, 0x1: band1
4088 * @ch: center channel
4089 * @band: band
4090 * @bw: bandwidth
4091 *
4092 * All channel and bandwidth related MAC setting would be done in
4093 * this function.
4094 * Following setting may be done in this functions:
4095 * a. Enable changing CCK data rate to OFDM 6M function
4096 * to avoid BB/RF abnormal when channel is not 2.4G.
4097 *
4098 * Return RTW_HAL_STATUS_SUCCESS when operation success.
4099 */
rtw_hal_mac_set_bw(struct hal_info_t * hal_info,u8 band_idx,u8 pri_ch,u8 central_ch_seg0,u8 central_ch_seg1,enum band_type band,enum channel_width bw)4100 enum rtw_hal_status rtw_hal_mac_set_bw(struct hal_info_t *hal_info,
4101 u8 band_idx, u8 pri_ch, u8 central_ch_seg0,
4102 u8 central_ch_seg1, enum band_type band,
4103 enum channel_width bw)
4104 {
4105 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4106 struct mac_ax_cfg_bw mac_bw = {0};
4107 u32 ret = 0;
4108
4109 mac_bw.cbw = bw;
4110 mac_bw.band = band_idx;
4111 mac_bw.pri_ch = pri_ch;
4112 mac_bw.central_ch = central_ch_seg0;
4113
4114 ret = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_BW_CFG, &mac_bw);
4115 return (ret == 0) ? (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
4116 }
4117
4118 /**
4119 * rtw_hal_mac_ax_init_bf_role
4120 * @bf_role: 0 = BFEE, 1 = BFER
4121 * @band: 0 = BAND0, 1 = BAND1
4122 */
4123 enum rtw_hal_status
rtw_hal_mac_ax_init_bf_role(struct rtw_hal_com_t * hal_com,u8 bf_role,u8 band)4124 rtw_hal_mac_ax_init_bf_role(struct rtw_hal_com_t *hal_com, u8 bf_role, u8 band)
4125 {
4126 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4127 struct hal_info_t *hal_info = hal_com->hal_priv;
4128 struct mac_ax_adapter *mac_info = hal_to_mac(hal_info);
4129
4130 if (bf_role == HAL_BF_ROLE_BFEE) {
4131 hal_status = mac_info->ops->init_snd_mee(
4132 mac_info, band);
4133 } else {
4134 hal_status = mac_info->ops->init_snd_mer(
4135 mac_info, band);
4136 };
4137 return hal_status;
4138 }
4139
4140
4141 /**
4142 * rtw_hal_mac_ax_disable_bfee
4143 * @band: 0 = BAND0, 1 = BAND1
4144 */
4145 enum rtw_hal_status
rtw_hal_mac_ax_deinit_bfee(struct rtw_hal_com_t * hal_com,u8 band)4146 rtw_hal_mac_ax_deinit_bfee(struct rtw_hal_com_t *hal_com, u8 band)
4147 {
4148 struct hal_info_t *hal_info = hal_com->hal_priv;
4149 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4150 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4151
4152 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4153 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "--> %s : Warning BFee is going to deinit\n", __func__);
4154
4155 hal_status = mac_info->ops->deinit_mee(mac_info, band);
4156
4157 return hal_status;
4158 }
4159
4160
4161 /**
4162 * rtw_hal_mac_ax_bfee_para_reg
4163 * Set BFee capability with STA info by method : Control Register
4164 * input:
4165 * @sta: (struct rtw_phl_stainfo_t *)
4166 */
4167 enum rtw_hal_status
rtw_hal_mac_ax_bfee_para_reg(void * mac,struct rtw_phl_stainfo_t * sta)4168 rtw_hal_mac_ax_bfee_para_reg(void *mac, struct rtw_phl_stainfo_t *sta)
4169 {
4170 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4171 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4172 struct rtw_hal_com_t *hal_com = (struct rtw_hal_com_t *)mac_info->drv_adapter;
4173 struct mac_reg_csi_para csi_para;
4174
4175 _os_mem_set(hal_com->drv_priv, &csi_para, 0, sizeof(csi_para));
4176
4177 csi_para.band = sta->wrole->hw_band;
4178 csi_para.portsel = (sta->wrole->hw_port == 0) ? 0 : 1;
4179 csi_para.nc = (sta->wrole->proto_role_cap.max_nc > sta->asoc_cap.num_snd_dim) ?
4180 sta->asoc_cap.num_snd_dim :
4181 sta->wrole->proto_role_cap.max_nc;
4182 csi_para.nr = (sta->wrole->proto_role_cap.bfme_sts >
4183 sta->asoc_cap.num_snd_dim) ?
4184 sta->asoc_cap.num_snd_dim :
4185 sta->wrole->proto_role_cap.bfme_sts;
4186 /**
4187 * For HE/VHT, Ng = 0 can provide the most detail information.
4188 * Ng do not care bfer cap.
4189 **/
4190 csi_para.ng = 0;
4191 /**
4192 * for HE/VHT, Cb = 1 {6,4}/{9,7} can provide the most detail information
4193 * Cb do not care bfer cap, only care bfee self capabiltiy.
4194 **/
4195 if (sta->wmode & WLAN_MD_11AX)
4196 csi_para.cb = sta->wrole->proto_role_cap.cb_sz_su_fb;
4197 else if (sta->wmode & WLAN_MD_11AC)
4198 csi_para.cb = sta->wrole->proto_role_cap.ht_vht_cb;
4199 else
4200 csi_para.cb = 0;
4201
4202 csi_para.cs = 1; /* Carrier Sense */
4203 if (sta->asoc_cap.ht_ldpc &&
4204 sta->asoc_cap.vht_ldpc &&
4205 sta->asoc_cap.he_ldpc)
4206 csi_para.ldpc_en = 1;
4207
4208 if (sta->asoc_cap.stbc_ht_rx &&
4209 sta->asoc_cap.stbc_vht_rx &&
4210 sta->asoc_cap.stbc_he_rx)
4211 csi_para.stbc_en = 1;
4212
4213 csi_para.bf_en = 0;
4214
4215 hal_status = mac_info->ops->set_csi_para_reg(mac_info, &csi_para);
4216
4217 return hal_status;
4218 }
4219
4220 /**
4221 * rtw_hal_mac_ax_bfee_para_cctl
4222 * Set BFee capability with STA info by method : CMAC Control Table
4223 * input:
4224 * @sta: (struct rtw_phl_stainfo_t *)
4225 */
4226 enum rtw_hal_status
rtw_hal_mac_ax_bfee_para_cctl(void * mac,struct rtw_phl_stainfo_t * sta)4227 rtw_hal_mac_ax_bfee_para_cctl(void *mac, struct rtw_phl_stainfo_t *sta)
4228 {
4229 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4230 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4231 struct rtw_hal_com_t *hal_com =
4232 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4233 struct mac_cctl_csi_para csi_para;
4234
4235 _os_mem_set(hal_com->drv_priv, &csi_para, 0, sizeof(csi_para));
4236
4237 csi_para.macid = (u8)sta->macid;
4238 csi_para.band = sta->wrole->hw_band;
4239 csi_para.nc = (sta->wrole->proto_role_cap.max_nc > sta->asoc_cap.num_snd_dim) ?
4240 sta->asoc_cap.num_snd_dim :
4241 sta->wrole->proto_role_cap.max_nc;
4242 csi_para.nr = (sta->wrole->proto_role_cap.bfme_sts >
4243 sta->asoc_cap.num_snd_dim) ?
4244 sta->asoc_cap.num_snd_dim :
4245 sta->wrole->proto_role_cap.bfme_sts;
4246 /**
4247 * For HE/VHT, Ng = 0 can provide the most detail information.
4248 * Ng do not care bfer cap.
4249 **/
4250 csi_para.ng = 0;
4251 /**
4252 * for HE/VHT, Cb = 1 {6,4}/{9,7} can provide the most detail information
4253 * Cb do not care bfer cap.
4254 **/
4255 if (sta->wmode & WLAN_MD_11AX)
4256 csi_para.cb = sta->wrole->proto_role_cap.cb_sz_su_fb;
4257 else if (sta->wmode & WLAN_MD_11AC)
4258 csi_para.cb = sta->wrole->proto_role_cap.ht_vht_cb;
4259 else
4260 csi_para.cb = 0;
4261 csi_para.cs = 1;
4262 csi_para.bf_en = 0;
4263
4264 if (sta->asoc_cap.stbc_ht_rx &&
4265 sta->asoc_cap.stbc_vht_rx &&
4266 sta->asoc_cap.stbc_he_rx)
4267 csi_para.stbc_en = 1;
4268
4269 if (sta->asoc_cap.ht_ldpc &&
4270 sta->asoc_cap.vht_ldpc &&
4271 sta->asoc_cap.he_ldpc)
4272 csi_para.ldpc_en = 1;
4273 csi_para.rate = MAC_AX_OFDM54;
4274 csi_para.gi_ltf = MAC_AX_SGI_4XHE08;
4275 csi_para.gid_sel = 1;
4276 csi_para.bw = MAC_AX_BW_20M;
4277
4278 hal_status = mac_info->ops->set_csi_para_cctl(mac_info, &csi_para);
4279 return hal_status;
4280 }
4281
4282 enum rtw_hal_status
rtw_hal_mac_ax_bfee_set_csi_rrsc(void * mac,u8 band,u32 rrsc)4283 rtw_hal_mac_ax_bfee_set_csi_rrsc(void *mac, u8 band, u32 rrsc)
4284 {
4285 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4286
4287 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4288
4289 hal_status = mac_info->ops->csi_rrsc(mac_info, band, rrsc);
4290
4291 return hal_status;
4292 }
4293
4294 /**
4295 * rtw_hal_mac_ax_bfee_forced_csi_rate
4296 * set bf report frame rate
4297 * @mac:(struct mac_ax_adapter *)
4298 * @ht_rate:
4299 * @vht_rate:
4300 * @he_rate:
4301 */
4302
4303 enum rtw_hal_status
rtw_hal_mac_ax_bfee_forced_csi_rate(void * mac,struct rtw_phl_stainfo_t * sta,u8 ht_rate,u8 vht_rate,u8 he_rate)4304 rtw_hal_mac_ax_bfee_forced_csi_rate(void *mac, struct rtw_phl_stainfo_t *sta,
4305 u8 ht_rate, u8 vht_rate, u8 he_rate)
4306 {
4307 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4308 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4309
4310 hal_status = mac_info->ops->csi_force_rate(mac_info,
4311 sta->wrole->hw_band, ht_rate, vht_rate, he_rate);
4312
4313 return hal_status;
4314 }
4315
4316 /**
4317 * rtw_hal_mac_ax_set_bf_entry
4318 * set HW BF entry for sounding and TxBF
4319 * input :
4320 * @band: BF Entry is band0 or band1;
4321 * @macid: BF Entry's macid
4322 * @bfee_idx: SU/MU HW Entry Index
4323 * @txbf_idx: Tx BF CSI Entry Index
4324 * @buffer_idx: CSI Buffer idx used by TxBF entry
4325 */
4326 enum rtw_hal_status
rtw_hal_mac_ax_set_bf_entry(void * mac,u8 band,u8 macid,u8 bfee_idx,u16 txbf_idx,u16 buffer_idx)4327 rtw_hal_mac_ax_set_bf_entry(void *mac, u8 band,
4328 u8 macid, u8 bfee_idx, u16 txbf_idx, u16 buffer_idx)
4329 {
4330 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4331 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4332 /* 1. CSI Buffer Idx */
4333 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "set_csi_buffer_index : band 0x%x macid 0x%x txbf_idx 0x%x buffer_idx 0x%x\n",
4334 band, macid, txbf_idx, buffer_idx);
4335 hal_status = mac_info->ops->set_csi_buffer_index(mac_info, band, macid,
4336 txbf_idx, buffer_idx);
4337
4338
4339 /*TODO: this api might revised in the future */
4340 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "set_snd_sts_index: band 0x%x macid 0x%x bf_idx 0x%x\n",
4341 band, macid, bfee_idx);
4342 hal_status = mac_info->ops->set_snd_sts_index(
4343 mac_info, band, macid, bfee_idx);
4344
4345
4346 return hal_status;
4347 }
4348
4349
4350 /**
4351 * rtw_hal_mac_ax_get_snd_sts
4352 * Get HW BF entry sounding status
4353 * input :
4354 * @band: BF Entry is band0 or band1;
4355 * @bfee_idx: SU/MU HW Entry Index
4356 * return
4357 * @hal_status: enum rtw_hal_status
4358 * RTW_HAL_STATUS_SUCCESS = Sounding Success
4359 * RTW_HAL_STATUS_FAILURE = Sounding Fail
4360 */
4361 enum rtw_hal_status
rtw_hal_mac_ax_get_snd_sts(void * mac,u8 band,u8 bfee_idx)4362 rtw_hal_mac_ax_get_snd_sts(void *mac, u8 band, u8 bfee_idx)
4363 {
4364 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4365 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4366 u32 sts = 0;
4367
4368 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "get_snd_sts_index: band 0x%x bf_idx 0x%x\n", band, bfee_idx);
4369 /*TODO: This API shall modify to return sounding status instead of CR value*/
4370 /*MAC Define : #define B_AX_MER_SU_BFMEE0_SND_STS BIT(9)*/
4371 sts = mac_info->ops->get_snd_sts_index(mac_info, band, bfee_idx);
4372 if (sts & B_AX_MER_SU_BFMEE0_SND_STS)
4373 hal_status = RTW_HAL_STATUS_SUCCESS;
4374
4375 return hal_status;
4376 }
4377
4378 /**
4379 * rtw_hal_mac_ax_hw_snd_control
4380 * @band: 0 = BAND0, 1 = BAND1
4381 * @hw_snd_ctrl: 0 = HW_SND_PAUSE 1 = HW_SND_RELEASE
4382 */
4383 enum rtw_hal_status
rtw_hal_mac_ax_hw_snd_control(void * mac,u8 band,u8 hw_snd_ctrl)4384 rtw_hal_mac_ax_hw_snd_control(
4385 void *mac,
4386 u8 band,
4387 u8 hw_snd_ctrl)
4388 {
4389 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4390 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4391 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_,
4392 "mac_hw_snd_pause_release: band 0x%x hw_snd_ctrl 0x%x\n",
4393 band, hw_snd_ctrl);
4394
4395 hal_status = mac_info->ops->hw_snd_pause_release(
4396 mac_info,
4397 band,
4398 hw_snd_ctrl);
4399
4400 return hal_status;
4401 }
4402
4403 /* Tx Frame Exchange Related : MU */
4404 /**
4405 * rtw_hal_mac_ax_mu_sta_upd
4406 * @mac: (struct mac_ax_adapter *)
4407 * @macid: sta macid for configuration
4408 * @bfmu_idx: 0~5, MU STA Index
4409 * @prot_type: RTS/CTS type for the group : enum rtw_hal_protection_type
4410 * @resp_type: Ack Policy for the group : enum rtw_hal_ack_resp_type
4411 * @grp_bitmap: group bitmap for STA,
4412 **/
4413 enum rtw_hal_status
rtw_hal_mac_ax_mu_sta_upd(void * mac,u8 macid,u8 bfmu_idx,enum rtw_hal_protection_type prot_type,enum rtw_hal_ack_resp_type resp_type,u8 mugrp_bm)4414 rtw_hal_mac_ax_mu_sta_upd(void *mac, u8 macid, u8 bfmu_idx,
4415 enum rtw_hal_protection_type prot_type,
4416 enum rtw_hal_ack_resp_type resp_type, u8 mugrp_bm)
4417 {
4418 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4419 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4420 struct rtw_hal_com_t *hal_com =
4421 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4422 struct mac_ax_mu_sta_upd sta_info;
4423 u8 i = 0;
4424
4425 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "==> rtw_hal_mac_ax_mu_sta_upd \n");
4426 _os_mem_set(hal_com->drv_priv, &sta_info, 0, sizeof(sta_info));
4427
4428 sta_info.macid = macid;
4429 sta_info.mu_idx = bfmu_idx;
4430 for (i = 0; i < 5; i++) {
4431 if (mugrp_bm & BIT(i)) {
4432 sta_info.prot_rsp_type[i].u.feld_type.protect =
4433 prot_type & 0xF;
4434 sta_info.prot_rsp_type[i].u.feld_type.rsp =
4435 resp_type & 0xF;
4436 } else {
4437 sta_info.prot_rsp_type[i].u.feld_type.protect = 0;
4438 sta_info.prot_rsp_type[i].u.feld_type.rsp = 0;
4439 }
4440 }
4441 sta_info.mugrp_bitmap = mugrp_bm & 0x1F;
4442
4443 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "sta_info.macid = 0x%x \n", sta_info.macid);
4444 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "sta_info.mu_idx = 0x%x \n", sta_info.mu_idx);
4445 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "sta_info.mugrp_bitmap = 0x%x \n", sta_info.mugrp_bitmap);
4446
4447 hal_status = mac_info->ops->mu_sta_upd(mac_info, &sta_info);
4448 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "<== rtw_hal_mac_ax_mu_sta_upd \n");
4449 return hal_status;
4450 }
4451
4452 /**
4453 * rtw_hal_mac_ax_mu_decision_para
4454 * @mac: (struct mac_ax_adapter *)
4455 * @mu_thold: MU MIMO pkt Threshold
4456 * @bypass_thold: by pass mu_thold
4457 * @bypass_tp: by pass MU TP > SU TP check.
4458 **/
4459 enum rtw_hal_status
rtw_hal_mac_ax_mu_decision_para(void * mac,u32 mu_thold,bool bypass_thold,bool bypass_tp)4460 rtw_hal_mac_ax_mu_decision_para(void *mac, u32 mu_thold,
4461 bool bypass_thold, bool bypass_tp)
4462 {
4463 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4464 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4465 struct rtw_hal_com_t *hal_com =
4466 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4467 struct mac_ax_mudecision_para mu_d_para;
4468
4469 _os_mem_set(hal_com->drv_priv, &mu_d_para, 0, sizeof(mu_d_para));
4470
4471 mu_d_para.mu_thold = mu_thold;
4472 mu_d_para.bypass_thold = bypass_thold ? 1 : 0;
4473 mu_d_para.bypass_tp = bypass_tp ? 1 : 0;
4474
4475 hal_status = mac_info->ops->upd_mudecision_para(mac_info, &mu_d_para);
4476
4477 return hal_status;
4478 }
4479
4480 /**
4481 * rtw_hal_mac_ax_set_mu_fix_mode
4482 * @mac: (struct mac_ax_adapter *)
4483 * @gid: GID for STA X + STAY
4484 * @prot_type: RTS/CTS type for the group : enum rtw_hal_protection_type
4485 * @resp_type: Ack Policy for the group : enum rtw_hal_ack_resp_type
4486 * @fix_mu: true = Fix FW decision = MU
4487 * @he: true = Fix TX HE MU, false = Fix TX VHT MU;
4488 * @fix_resp: fix frame exchange ack policy
4489 * @fix_prot: fix frame exchange protection type
4490 **/
4491 enum rtw_hal_status
rtw_hal_mac_ax_set_mu_fix_mode(void * mac,u8 gid,enum rtw_hal_protection_type prot_type,enum rtw_hal_ack_resp_type resp_type,bool fix_mu,bool he,bool fix_resp,bool fix_prot)4492 rtw_hal_mac_ax_set_mu_fix_mode(
4493 void *mac, u8 gid, enum rtw_hal_protection_type prot_type,
4494 enum rtw_hal_ack_resp_type resp_type,
4495 bool fix_mu, bool he, bool fix_resp, bool fix_prot)
4496 {
4497 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4498 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4499 struct rtw_hal_com_t *hal_com =
4500 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4501 struct mac_ax_fixmode_para fix_info;
4502 PHL_INFO("===>rtw_hal_mac_ax_set_mu_fix_mode\n");
4503
4504 _os_mem_set(hal_com->drv_priv, &fix_info, 0, sizeof(fix_info));
4505
4506 fix_info.force_sumuru_en = fix_mu ? 1:0 ;
4507 fix_info.forcemu = fix_mu ? 1:0 ;
4508
4509 if (fix_mu) {
4510 if (!he){
4511 fix_info.fix_fe_vhtmu_en = fix_prot ? 1 : 0;
4512 fix_info.fix_frame_seq_vhtmu = fix_resp ? 1 : 0;
4513 fix_info.prot_type_vhtmu = fix_prot ? prot_type : 5;/*default hw setting*/
4514 fix_info.resp_type_vhtmu = fix_resp ? resp_type : 4;/*default hw setting*/
4515 PHL_INFO("fix_info.prot_type_vhtmu = 0x%x\n", fix_info.prot_type_vhtmu);
4516 PHL_INFO("fix_info.resp_type_vhtmu = 0x%x\n", fix_info.resp_type_vhtmu);
4517
4518 } else {
4519 fix_info.fix_fe_hemu_en = fix_prot ? 1 : 0;;
4520 fix_info.fix_frame_seq_hemu = fix_resp ? 1 : 0;
4521 fix_info.prot_type_hemu = fix_prot ? prot_type : 5;/*default hw setting*/
4522 fix_info.resp_type_hemu = fix_resp ? resp_type : 4;/*default hw setting*/
4523 PHL_INFO("fix_info.prot_type_hemu = 0x%x\n", fix_info.prot_type_hemu);
4524 PHL_INFO("fix_info.resp_type_hemu = 0x%x\n", fix_info.resp_type_hemu);
4525 }
4526
4527 fix_info.mugrpid = gid;
4528 PHL_INFO("fix_info.mugrpid = 0x%x\n", fix_info.mugrpid);
4529 }
4530
4531 hal_status = mac_info->ops->set_fw_fixmode(mac_info, &fix_info);
4532 PHL_INFO("<===rtw_hal_mac_ax_set_mu_fix_mode\n");
4533 return hal_status;
4534 }
4535
4536
4537 void
_hal_mac_fill_mu_sc_tbl_row(u32 * mac_score,void * hal_score)4538 _hal_mac_fill_mu_sc_tbl_row(u32 *mac_score, void *hal_score)
4539 {
4540 struct hal_mu_score_tbl_score *h_score =
4541 (struct hal_mu_score_tbl_score *)hal_score;
4542
4543 *mac_score = (u32)h_score->score[0] |
4544 ((u32)h_score->score[1] << 8) | ((u32)h_score->valid << 10) |
4545 ((u32)h_score->macid << 11);
4546
4547 }
4548 /**
4549 * rtw_hal_mac_ax_set_mu_table_whole
4550 * @mac: (struct mac_ax_adapter *)
4551 *@hal_score_tbl: struct hal_mu_score_tbl *
4552 */
4553 enum rtw_hal_status
rtw_hal_mac_ax_set_mu_table_whole(void * mac,void * hal_score_tbl)4554 rtw_hal_mac_ax_set_mu_table_whole(void *mac, void *hal_score_tbl)
4555 {
4556 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4557 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4558 struct rtw_hal_com_t *hal_com =
4559 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4560 struct mac_mu_table mu_table;
4561 struct hal_mu_score_tbl *score_tbl = (struct hal_mu_score_tbl *)hal_score_tbl;
4562 _os_mem_set(hal_com->drv_priv, &mu_table, 0, sizeof(mu_table));
4563
4564 /*TODO: halmac api shall refine!!!*/
4565 mu_table.mu_score_tbl_ctrl = (score_tbl->mu_ctrl.mu_sc_thr) |
4566 (score_tbl->mu_ctrl.mu_opt << 2);
4567
4568 /*TODO: if next IC has more than 6 MU STAs!!! */
4569 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_0, &score_tbl->mu_score[0]);
4570 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_1, &score_tbl->mu_score[1]);
4571 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_2, &score_tbl->mu_score[2]);
4572 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_3, &score_tbl->mu_score[3]);
4573 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_4, &score_tbl->mu_score[4]);
4574 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_5, &score_tbl->mu_score[5]);
4575
4576 hal_status = mac_info->ops->set_mu_table(mac_info, &mu_table);
4577
4578 return hal_status;
4579 }
4580
4581
4582 enum rtw_hal_status
rtw_hal_mac_parse_c2h(void * hal,u8 * buf,u32 buf_len,void * c2h)4583 rtw_hal_mac_parse_c2h(void *hal, u8 *buf, u32 buf_len, void *c2h)
4584 {
4585 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4586 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
4587 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4588
4589 hal_status = mac->ops->process_c2h(mac, buf, buf_len, (u8 *)c2h);
4590
4591 return hal_status;
4592 }
4593
4594 /**
4595 * Required information in (hal_handle_rx_buffer_XXXXX case RX_DESC_PKT_TYPE_PPDU_STATUS),
4596 * it cannot be used by core/phl/other hal module
4597 **/
4598 void
_hal_mac_ax_ppdu_sts_to_hal_ppdu_sts(struct mac_ax_ppdu_rpt * mac_ppdu,void * hal_ppdu_sts)4599 _hal_mac_ax_ppdu_sts_to_hal_ppdu_sts(
4600 struct mac_ax_ppdu_rpt *mac_ppdu, void *hal_ppdu_sts)
4601 {
4602 struct hal_ppdu_sts *hal_ppdu =
4603 (struct hal_ppdu_sts *)hal_ppdu_sts;
4604 u8 i = 0;
4605 u32 j = 0;
4606
4607 hal_ppdu->rx_cnt_ptr = mac_ppdu->rx_cnt_ptr;
4608 hal_ppdu->phy_st_ptr = mac_ppdu->phy_st_ptr;
4609 hal_ppdu->plcp_ptr = mac_ppdu->plcp_ptr;
4610 hal_ppdu->plcp_size = mac_ppdu->plcp_size;
4611 hal_ppdu->phy_st_size = mac_ppdu->phy_st_size;
4612 hal_ppdu->rx_cnt_size = mac_ppdu->rx_cnt_size;
4613 hal_ppdu->usr_num = mac_ppdu->usr_num;
4614 for(i = 0; i < mac_ppdu->usr_num; i++) {
4615 if(1 == mac_ppdu->usr[i].vld) {
4616 hal_ppdu->usr[i].vld = 1;
4617 hal_ppdu->usr[i].macid = mac_ppdu->usr[i].macid;
4618 hal_ppdu->usr[i].has_data = mac_ppdu->usr[i].has_data;
4619 hal_ppdu->usr[i].has_ctrl = mac_ppdu->usr[i].has_ctrl;
4620 hal_ppdu->usr[i].has_mgnt = mac_ppdu->usr[i].has_mgnt;
4621 hal_ppdu->usr[i].has_bcn = mac_ppdu->usr[i].has_bcn;
4622 }
4623 }
4624 /* process / decode rx cnt report */
4625 /* TODO: Halmac api shall provid decoder */
4626 if ((0 != hal_ppdu->rx_cnt_size) && (NULL != hal_ppdu->rx_cnt_ptr)) {
4627 for(j = 0; (j < (hal_ppdu->rx_cnt_size/2)) &&
4628 (j < HAL_RXCNT_MAX); j++) {
4629 hal_ppdu->rx_cnt.ppdu_cnt[j] =
4630 ((u16)*(hal_ppdu->rx_cnt_ptr + 2 * j));
4631 }
4632 }
4633 }
4634
4635 /**
4636 * if any information is required for other core/phl module,
4637 * copy to rx meta data or hal_info from halmac ax ppdu status.
4638 **/
4639 void
_hal_mac_ax_ppdu_sts_to_hal_info(struct hal_info_t * hal_info,struct mac_ax_ppdu_rpt * mac_ppdu,void * rx_mdata)4640 _hal_mac_ax_ppdu_sts_to_hal_info(struct hal_info_t *hal_info,
4641 struct mac_ax_ppdu_rpt *mac_ppdu, void *rx_mdata)
4642 {
4643 /* struct rtw_r_meta_data *mdata =
4644 (struct rtw_r_meta_data *)rx_mdata; */
4645 return;
4646 }
4647 /**
4648 * rtw_hal_mac_ax_parse_ppdu_sts
4649 * @hal:(struct hal_info_t *)
4650 * @mac_valid:if mac information invalid (from rx desc)
4651 * @buf: pointer of ppdu status, point to header of mac_info
4652 * @buf_l:ppdu status payload size
4653 * @ppdu_sts: (struct hal_ppdu_sts *) for return value to hal
4654 * @rx_mdata: (struct rtw_r_meta_data *) for saving ppdu status
4655 */
4656 enum rtw_hal_status
rtw_hal_mac_ax_parse_ppdu_sts(void * hal,u8 mac_valid,u8 * buf,u16 buf_l,void * ppdu_sts,void * rx_mdata)4657 rtw_hal_mac_ax_parse_ppdu_sts(void *hal, u8 mac_valid, u8 *buf, u16 buf_l,
4658 void *ppdu_sts, void *rx_mdata)
4659 {
4660 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
4661 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
4662 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4663 struct mac_ax_ppdu_rpt ppdu_rpt = {0};
4664
4665 PHL_DBG("%s\n", __FUNCTION__);
4666
4667 hal_status = mac->ops->parse_ppdu(hal_info->mac, buf, buf_l,
4668 mac_valid, &ppdu_rpt);
4669
4670 if (hal_status == RTW_HAL_STATUS_SUCCESS) {
4671 _hal_mac_ax_ppdu_sts_to_hal_ppdu_sts(&ppdu_rpt, ppdu_sts);
4672 _hal_mac_ax_ppdu_sts_to_hal_info(hal_info ,&ppdu_rpt,
4673 rx_mdata);
4674 }
4675
4676 return hal_status;
4677 }
4678
4679
4680 /**
4681 * the function to enable HW header conversion function
4682 * @hal_info: see struct hal_info_t
4683 * @en_hdr_conv: true to enable, false to disable
4684 *
4685 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4686 */
rtw_hal_hdr_conv_cfg(struct hal_info_t * hal_info,u8 en_hdr_conv)4687 enum rtw_hal_status rtw_hal_hdr_conv_cfg(struct hal_info_t *hal_info,
4688 u8 en_hdr_conv)
4689 {
4690 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4691 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4692 u32 ret = 0;
4693
4694 ret = mac->ops->hdr_conv(mac, en_hdr_conv);
4695
4696 if (MACSUCCESS == ret) {
4697 sts = RTW_HAL_STATUS_SUCCESS;
4698 } else {
4699 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "hdr_conv fail (0x%08X)\n",
4700 ret);
4701 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4702 }
4703
4704 return sts;
4705 }
4706
4707
4708 #ifdef RTW_PHL_BCN //fill hal mac ops
4709 enum rtw_hal_status
hal_mac_ax_config_beacon(struct hal_info_t * hal,struct rtw_bcn_entry * bcn_entry)4710 hal_mac_ax_config_beacon(struct hal_info_t *hal, struct rtw_bcn_entry *bcn_entry)
4711 {
4712 struct mac_ax_adapter *mac = hal_to_mac(hal);
4713 struct rtw_bcn_info_cmn *bcn_cmn = bcn_entry->bcn_cmn;
4714 struct rtw_bcn_info_hw *bcn_hw = &bcn_entry->bcn_hw;
4715 enum mac_ax_port_cfg_type ptype;
4716 struct mac_ax_port_cfg_para ppara = {0};
4717
4718 ppara.band = bcn_hw->band;
4719 ppara.port = bcn_hw->port;
4720 ppara.mbssid_idx = bcn_hw->mbssid;
4721
4722 ptype = MAC_AX_PCFG_BCN_INTV;
4723 ppara.val = bcn_cmn->bcn_interval;
4724 if (mac->ops->port_cfg(mac, ptype, &ppara) != MACSUCCESS)
4725 return RTW_HAL_STATUS_FAILURE;
4726
4727 ptype = MAC_AX_PCFG_HIQ_DTIM;
4728 ppara.val = bcn_cmn->bcn_dtim;
4729 if (mac->ops->port_cfg(mac, ptype, &ppara) != MACSUCCESS)
4730 return RTW_HAL_STATUS_FAILURE;
4731
4732 return RTW_HAL_STATUS_SUCCESS;
4733 }
4734
4735 enum rtw_hal_status
hal_mac_ax_send_beacon(struct hal_info_t * hal,struct rtw_bcn_entry * bcn_entry)4736 hal_mac_ax_send_beacon(struct hal_info_t *hal, struct rtw_bcn_entry *bcn_entry)
4737 {
4738
4739 struct mac_ax_adapter *mac = hal_to_mac(hal);
4740 struct rtw_bcn_info_cmn *bcn_cmn = bcn_entry->bcn_cmn;
4741 struct rtw_bcn_info_hw *bcn_hw = &bcn_entry->bcn_hw;
4742 struct mac_ax_bcn_info info = {0};
4743
4744 if(!mac->ops->send_bcn_h2c)
4745 return RTW_HAL_STATUS_FAILURE;
4746
4747 info.pld_buf = bcn_cmn->bcn_buf;
4748 info.pld_len = (u16)bcn_cmn->bcn_length;
4749
4750 info.band = bcn_hw->band;
4751 info.port = bcn_hw->port;
4752 info.mbssid = bcn_hw->mbssid;
4753 info.grp_ie_ofst = (u8)bcn_cmn->ie_offset_tim;
4754 info.macid = bcn_hw->mac_id;
4755
4756 if(bcn_cmn->bcn_offload & BIT(BCN_HW_TIM))
4757 info.grp_ie_ofst |= BIT(7);
4758
4759 if(bcn_cmn->bcn_offload & BIT(BCN_HW_SEQ)){
4760 info.ssn_sel = 1;
4761 info.ssn_mode = 1;
4762 }
4763 else {
4764 info.ssn_sel = 0;
4765 info.ssn_mode = 0;
4766 }
4767
4768 info.rate_sel = (u16)bcn_cmn->bcn_rate;
4769
4770 mac->ops->send_bcn_h2c(mac, &info);
4771
4772 return RTW_HAL_STATUS_SUCCESS;
4773
4774 }
4775 #endif //RTW_PHL_BCN
4776
4777 enum rtw_hal_status
rtw_hal_mac_ppdu_stat_cfg(struct hal_info_t * hal_info,u8 band_idx,bool ppdu_stat_en,u8 appen_info,u8 filter)4778 rtw_hal_mac_ppdu_stat_cfg(struct hal_info_t *hal_info,
4779 u8 band_idx,
4780 bool ppdu_stat_en,
4781 u8 appen_info,
4782 u8 filter)
4783 {
4784 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4785 struct mac_ax_phy_rpt_cfg cfg = {0};
4786
4787 cfg.en = ppdu_stat_en;
4788 cfg.type = MAC_AX_PPDU_STATUS;
4789 /*cfg.dest = MAC_AX_PRPT_DEST_HOST;*/
4790
4791 cfg.u.ppdu.band = band_idx;
4792 if (ppdu_stat_en) {
4793 if (appen_info&HAL_PPDU_MAC_INFO)
4794 cfg.u.ppdu.bmp_append_info |= MAC_AX_PPDU_MAC_INFO;
4795 if (appen_info&HAL_PPDU_PLCP)
4796 cfg.u.ppdu.bmp_append_info |= MAC_AX_PPDU_PLCP;
4797 if (appen_info&HAL_PPDU_RX_CNT)
4798 cfg.u.ppdu.bmp_append_info |= MAC_AX_PPDU_RX_CNT;
4799
4800 if (filter&HAL_PPDU_HAS_A1M)
4801 cfg.u.ppdu.bmp_filter |= MAC_AX_PPDU_HAS_A1M;
4802 if (filter&HAL_PPDU_HAS_CRC_OK)
4803 cfg.u.ppdu.bmp_filter |= MAC_AX_PPDU_HAS_CRC_OK;
4804
4805 cfg.u.ppdu.dup2fw_en = false;
4806 cfg.u.ppdu.dup2fw_len = 0;
4807 }
4808
4809 if (mac->ops->cfg_phy_rpt(mac, &cfg) != MACSUCCESS) {
4810 PHL_ERR("%s fault\n", __func__);
4811 return RTW_HAL_STATUS_FAILURE;
4812 }
4813 return RTW_HAL_STATUS_SUCCESS;
4814 }
4815
rtw_hal_mac_config_hw_mgnt_sec(struct hal_info_t * hal_info,u8 en)4816 enum rtw_hal_status rtw_hal_mac_config_hw_mgnt_sec(struct hal_info_t *hal_info, u8 en)
4817 {
4818 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4819 struct mac_ax_ops *hal_mac_ops = mac->ops;
4820
4821 hal_mac_ops->sta_hw_security_support(mac, SEC_UC_MGNT_ENC, en);
4822 hal_mac_ops->sta_hw_security_support(mac, SEC_BMC_MGNT_ENC, en);
4823
4824 return RTW_HAL_STATUS_SUCCESS;
4825 }
4826
rtw_hal_mac_get_append_fcs(struct hal_info_t * hal_info,u8 * val)4827 enum rtw_hal_status rtw_hal_mac_get_append_fcs(struct hal_info_t *hal_info, u8 *val)
4828 {
4829 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4830 struct mac_ax_ops *ops = mac->ops;
4831
4832 if (ops->get_hw_value(mac, MAC_AX_HW_GET_APP_FCS, val) != MACSUCCESS)
4833 return RTW_HAL_STATUS_FAILURE;
4834 else
4835 return RTW_HAL_STATUS_SUCCESS;
4836 }
4837
rtw_hal_mac_get_acpt_icv_err(struct hal_info_t * hal_info,u8 * val)4838 enum rtw_hal_status rtw_hal_mac_get_acpt_icv_err(struct hal_info_t *hal_info, u8 *val)
4839 {
4840 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4841 struct mac_ax_ops *ops = mac->ops;
4842
4843 if (ops->get_hw_value(mac, MAC_AX_HW_GET_RX_ICVERR, val) != MACSUCCESS)
4844 return RTW_HAL_STATUS_FAILURE;
4845 else
4846 return RTW_HAL_STATUS_SUCCESS;
4847 }
4848
4849 #ifdef CONFIG_PHL_CHANNEL_INFO
4850 enum rtw_hal_status
rtw_hal_mac_chan_info_cfg(struct hal_info_t * hal_info,bool chinfo_en,u8 macid,u8 mode,u8 filter,u8 sg_size)4851 rtw_hal_mac_chan_info_cfg(struct hal_info_t *hal_info,
4852 bool chinfo_en, u8 macid,
4853 u8 mode, u8 filter, u8 sg_size)
4854 {
4855 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4856 struct mac_ax_phy_rpt_cfg cfg = {0};
4857
4858 cfg.en = chinfo_en;
4859 cfg.type = MAC_AX_CH_INFO;
4860 /*cfg.dest = MAC_AX_PRPT_DEST_HOST;*/
4861 cfg.u.chif.macid = macid;
4862
4863 if (chinfo_en) {
4864 /*ToDo - mode*/
4865 cfg.u.chif.trigger = MAC_AX_CH_INFO_MACID;
4866 /*ToDo - filter*/
4867 cfg.u.chif.bmp_filter = MAC_AX_CH_INFO_DATA_FRM;
4868 cfg.u.chif.dis_to = 0;
4869 /*ToDo - sg_size*/
4870 cfg.u.chif.seg_size = MAC_AX_CH_IFNO_SEG_512;
4871 }
4872 if (mac->ops->cfg_phy_rpt(mac, &cfg) != MACSUCCESS) {
4873 PHL_ERR("%s fault\n", __func__);
4874 return RTW_HAL_STATUS_FAILURE;
4875 }
4876 return RTW_HAL_STATUS_SUCCESS;
4877 }
4878 #endif /* CONFIG_PHL_CHANNEL_INFO */
4879
rtw_hal_mac_dbg_status_dump(struct hal_info_t * hal,struct hal_mac_dbg_dump_cfg * cfg)4880 void rtw_hal_mac_dbg_status_dump(struct hal_info_t *hal, struct hal_mac_dbg_dump_cfg *cfg)
4881 {
4882 struct mac_ax_adapter *mac = hal_to_mac(hal);
4883 struct mac_ax_dbgpkg pkg = {0};
4884 struct mac_ax_dbgpkg_en pkg_en = {0};
4885
4886 pkg.ss_dbg_0 = cfg->ss_dbg_0;
4887 pkg.ss_dbg_1 = cfg->ss_dbg_1;
4888
4889 pkg_en.ss_dbg = cfg->ss_dbg;
4890 pkg_en.dle_dbg = cfg->dle_dbg;
4891 pkg_en.dmac_dbg = cfg->dmac_dbg;
4892 pkg_en.cmac_dbg = cfg->cmac_dbg;
4893 pkg_en.mac_dbg_port = cfg->mac_dbg_port;
4894 pkg_en.plersvd_dbg = cfg->plersvd_dbg;
4895 pkg_en.tx_flow_dbg = cfg->tx_flow_dbg;
4896
4897 PHL_INFO("%s: ss_dbg_0 %d, ss_dbg_1 %d, ss_dbg %d\n", __func__, pkg.ss_dbg_0, pkg.ss_dbg_1, pkg_en.ss_dbg);
4898 PHL_INFO("%s: dle_dbg %d, dmac_dbg %d, cmac_dbg %d\n", __func__, pkg_en.dle_dbg, pkg_en.dmac_dbg, pkg_en.cmac_dbg);
4899 PHL_INFO("%s: mac_dbg_port %d, plersvd_dbg %d, tx_flow_dbg %d\n", __func__, pkg_en.mac_dbg_port, pkg_en.plersvd_dbg, pkg_en.tx_flow_dbg);
4900
4901 mac->ops->dbg_status_dump(mac, &pkg, &pkg_en);
4902 }
4903
4904 #ifdef CONFIG_PHL_DFS
4905 enum rtw_hal_status
rtw_hal_mac_dfs_rpt_cfg(struct hal_info_t * hal_info,bool rpt_en,u8 rpt_num,u8 rpt_to)4906 rtw_hal_mac_dfs_rpt_cfg(struct hal_info_t *hal_info,
4907 bool rpt_en, u8 rpt_num, u8 rpt_to)
4908 {
4909 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4910 struct mac_ax_phy_rpt_cfg cfg = {0};
4911
4912 cfg.en = rpt_en;
4913 cfg.type = MAC_AX_DFS;
4914 /*cfg.dest = MAC_AX_PRPT_DEST_HOST;*/
4915
4916 if (rpt_en) {
4917 cfg.u.dfs.num_th = rpt_num;
4918 cfg.u.dfs.en_timeout = rpt_to;
4919 }
4920
4921 if (mac->ops->cfg_phy_rpt(mac, &cfg) != MACSUCCESS) {
4922 PHL_ERR("%s fault\n", __func__);
4923 return RTW_HAL_STATUS_FAILURE;
4924 }
4925 return RTW_HAL_STATUS_SUCCESS;
4926 }
4927
4928 enum rtw_hal_status
rtw_hal_mac_parse_dfs(struct hal_info_t * hal_info,u8 * buf,u32 buf_len,struct mac_ax_dfs_rpt * dfs_rpt)4929 rtw_hal_mac_parse_dfs(struct hal_info_t *hal_info,
4930 u8 *buf, u32 buf_len, struct mac_ax_dfs_rpt *dfs_rpt)
4931 {
4932 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4933
4934 if (mac->ops->parse_dfs(mac, buf, buf_len, dfs_rpt) != MACSUCCESS) {
4935 PHL_ERR("%s fault\n", __func__);
4936 return RTW_HAL_STATUS_FAILURE;
4937 }
4938
4939 return RTW_HAL_STATUS_SUCCESS;
4940 }
4941 #endif /*CONFIG_PHL_DFS*/
4942
4943 enum rtw_hal_status
_hal_mac_get_pkt_ofld(struct hal_info_t * hal_info,u8 * id)4944 _hal_mac_get_pkt_ofld(struct hal_info_t *hal_info, u8 *id)
4945 {
4946 struct rtw_hal_com_t *hal_com = hal_info->hal_com;
4947 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4948 u8 *pkt_buf = NULL;
4949 u16 pkt_len;
4950
4951 if(mac == NULL)
4952 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
4953
4954 if (mac->ops->pkt_ofld_packet(mac, &pkt_buf, &pkt_len, id) != MACSUCCESS)
4955 return RTW_HAL_STATUS_FAILURE;
4956
4957 debug_dump_data((u8 *)pkt_buf, pkt_len, "pkt ofld");
4958
4959 _os_mem_free(hal_com->drv_priv, pkt_buf, pkt_len);
4960
4961 return RTW_HAL_STATUS_SUCCESS;
4962 }
4963
4964 enum rtw_hal_status
_hal_mac_chk_pkt_ofld(struct hal_info_t * hal_info)4965 _hal_mac_chk_pkt_ofld(struct hal_info_t *hal_info)
4966 {
4967 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4968 void *d = hal_to_drvpriv(hal_info);
4969 u16 loop_cnt = 0;
4970
4971 if(mac == NULL)
4972 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
4973
4974 do
4975 {
4976 if (mac->ops->check_fwofld_done(mac, 1) == MACSUCCESS)
4977 break;
4978
4979 _os_sleep_ms(d, POLLING_HALMAC_TIME);
4980
4981 loop_cnt++;
4982 } while (loop_cnt < POLLING_HALMAC_CNT);
4983
4984 if ( loop_cnt < POLLING_HALMAC_CNT) {
4985 PHL_PRINT("%s, check count = %d.\n", __func__, loop_cnt);
4986 return RTW_HAL_STATUS_SUCCESS;
4987 } else {
4988 PHL_ERR("%s, polling timeout!!!\n", __func__);
4989 return RTW_HAL_STATUS_FAILURE;
4990 }
4991 }
4992
4993 enum rtw_hal_status
_hal_mac_add_pkt_ofld(struct hal_info_t * hal_info,u8 * pkt,u16 len,u8 * id)4994 _hal_mac_add_pkt_ofld(struct hal_info_t *hal_info, u8 *pkt, u16 len, u8 *id)
4995 {
4996 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4997 u32 status;
4998
4999 if(mac == NULL)
5000 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5001
5002 PHL_PRINT("%s: len %d.\n", __func__, len);
5003
5004 status = mac->ops->add_pkt_ofld(mac, pkt, len, id);
5005 if (status != MACSUCCESS) {
5006 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5007 return RTW_HAL_STATUS_FAILURE;
5008 }
5009 PHL_PRINT("%s: id %d.\n", __func__, *id);
5010
5011 status = _hal_mac_chk_pkt_ofld(hal_info);
5012 return status;
5013 }
5014
5015 enum rtw_hal_status
_hal_mac_del_pkt_ofld(struct hal_info_t * hal_info,u8 * id)5016 _hal_mac_del_pkt_ofld(struct hal_info_t *hal_info, u8 *id)
5017 {
5018 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5019 u32 status;
5020
5021 if(mac == NULL)
5022 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5023
5024 PHL_PRINT("%s: id %d.\n", __func__, *id);
5025
5026 status = mac->ops->del_pkt_ofld(mac, *id);
5027 if (status != MACSUCCESS) {
5028 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5029 return RTW_HAL_STATUS_FAILURE;
5030 }
5031
5032 status = _hal_mac_chk_pkt_ofld(hal_info);
5033 return RTW_HAL_STATUS_SUCCESS;
5034 }
5035
5036 enum rtw_hal_status
_hal_mac_read_pkt_ofld(struct hal_info_t * hal_info,u8 * id)5037 _hal_mac_read_pkt_ofld(struct hal_info_t *hal_info, u8 *id)
5038 {
5039 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5040 u32 status;
5041
5042 if(mac == NULL)
5043 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5044
5045 PHL_PRINT("%s: id %d.\n", __func__, *id);
5046
5047 status = mac->ops->read_pkt_ofld(mac, *id);
5048 if (status != MACSUCCESS) {
5049 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5050 return RTW_HAL_STATUS_FAILURE;
5051 }
5052
5053 status = _hal_mac_chk_pkt_ofld(hal_info);
5054 if (status != MACSUCCESS) {
5055 return RTW_HAL_STATUS_FAILURE;
5056 }
5057
5058 status = _hal_mac_get_pkt_ofld(hal_info, id);
5059 return RTW_HAL_STATUS_SUCCESS;
5060 }
5061
rtw_hal_mac_pkt_ofld(struct hal_info_t * hal,u8 * id,u8 op,u8 * pkt,u16 * len)5062 enum rtw_hal_status rtw_hal_mac_pkt_ofld(struct hal_info_t *hal, u8 *id, u8 op,
5063 u8 *pkt, u16 *len)
5064 {
5065 enum rtw_hal_status status = RTW_HAL_STATUS_FAILURE;
5066
5067 switch(op) {
5068 case PKT_OFLD_ADD:
5069 status = _hal_mac_add_pkt_ofld(hal, pkt, *len, id);
5070 break;
5071
5072 case PKT_OFLD_DEL:
5073 status = _hal_mac_del_pkt_ofld(hal, id);
5074 break;
5075
5076 case PKT_OFLD_READ:
5077 status = _hal_mac_read_pkt_ofld(hal, id);
5078 break;
5079
5080 default:
5081 PHL_ERR("%s op(%d) not define.\n", __func__, op);
5082 break;
5083 }
5084
5085 return status;
5086 }
5087
rtw_hal_mac_pkt_update_ids(struct hal_info_t * hal,struct pkt_ofld_entry * entry)5088 enum rtw_hal_status rtw_hal_mac_pkt_update_ids(struct hal_info_t *hal,
5089 struct pkt_ofld_entry *entry)
5090 {
5091 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal->mac;
5092 struct mac_ax_general_pkt_ids mac_ids = {0};
5093 u32 status;
5094
5095 mac_ids.macid = (u8)entry->macid;
5096 mac_ids.probersp = entry->pkt_info[PKT_TYPE_PROBE_RSP].id;
5097 mac_ids.pspoll = entry->pkt_info[PKT_TYPE_PS_POLL].id;
5098 mac_ids.nulldata = entry->pkt_info[PKT_TYPE_NULL_DATA].id;
5099 mac_ids.qosnull = entry->pkt_info[PKT_TYPE_QOS_NULL].id;
5100 mac_ids.cts2self = entry->pkt_info[PKT_TYPE_CTS2SELF].id;
5101
5102 PHL_PRINT("macid %d, probersp %d, pspoll %d, nulldata %d, qosnull %d, cts2self %d.\n",
5103 mac_ids.macid,
5104 mac_ids.probersp,
5105 mac_ids.pspoll,
5106 mac_ids.nulldata,
5107 mac_ids.qosnull,
5108 mac_ids.cts2self);
5109
5110 status = mac->ops->general_pkt_ids(mac, &mac_ids);
5111 if (status != MACSUCCESS) {
5112 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5113 return RTW_HAL_STATUS_FAILURE;
5114 }
5115 return status;
5116 }
5117 enum rtw_hal_status
rtw_hal_mac_reset_pkt_ofld_state(struct hal_info_t * hal_info)5118 rtw_hal_mac_reset_pkt_ofld_state(struct hal_info_t *hal_info)
5119 {
5120 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5121
5122 if (mac == NULL)
5123 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5124
5125 if (mac->ops->reset_fwofld_state(mac, 1) != MACSUCCESS)
5126 return RTW_HAL_STATUS_FAILURE;
5127 else
5128 return RTW_HAL_STATUS_SUCCESS;
5129
5130 }
5131
5132 /* comment temporary and review it later */
5133 #if 0
5134 u4Byte hal_mac_ax_dbg_h2cpkt_lb(RT_HAL_MAC_INFO *hm_info, u32 size)
5135 {
5136 PADAPTER adapter = hm_info->adapter;
5137 u32 ret = 0;
5138
5139 u8 *h2cbuf = NULL;
5140 FunctionIn(COMP_HAL_MAC_API);
5141
5142 //ret = hm_info->halmac_ax_ops->fwcmd_lb(hm_info->halmac_ax_apter,
5143 // 100, 0);
5144
5145 PlatformAllocateMemory(adapter, (PVOID *)&h2cbuf, size);
5146 PlatformZeroMemory(h2cbuf,size);
5147
5148 for (u4Byte tmpc = 0; tmpc < size - 32; tmpc++) {
5149 h2cbuf[32 + tmpc] = (u8)tmpc & 0xFF;
5150 }
5151
5152 hal_mac_ax_send_h2c_pkt(adapter, h2cbuf, size);
5153
5154 PlatformFreeMemory(h2cbuf, size);
5155
5156 FunctionOut(COMP_HAL_MAC_API);
5157 return ret;
5158 }
5159
5160
5161 u4Byte hal_mac_ax_update_table_dl_swru(RT_HAL_MAC_INFO *hm_info,
5162 struct ofdma_dl_group *dl_group)
5163 {
5164 PADAPTER adapter = hm_info->adapter;
5165 u32 ret=0;
5166 FunctionIn(COMP_HAL_MAC_API);
5167
5168 ret = hm_info->halmac_ax_ops->upd_dlru_grptbl(
5169 hm_info->halmac_ax_apter,
5170 &dl_group->dl_grp_table);
5171
5172
5173 FunctionOut(COMP_HAL_MAC_API);
5174 return ret;
5175 }
5176
5177 u4Byte hal_mac_ax_update_table_dl_swfix(RT_HAL_MAC_INFO *hm_info,
5178 struct ofdma_dl_group *dl_group)
5179 {
5180 PADAPTER adapter = hm_info->adapter;
5181 u32 ret=0;
5182 FunctionIn(COMP_HAL_MAC_API);
5183
5184 ret = hm_info->halmac_ax_ops->upd_dlru_fixtbl(
5185 hm_info->halmac_ax_apter,
5186 &dl_group->fixed_mode_group);
5187
5188
5189 FunctionOut(COMP_HAL_MAC_API);
5190 return ret;
5191 }
5192
5193
5194 u4Byte hal_mac_ax_update_table_ul_rufix(RT_HAL_MAC_INFO *hm_info,
5195 struct ofdma_ul_group *ul_group)
5196 {
5197 PADAPTER adapter = hm_info->adapter;
5198 u32 ret=0;
5199 FunctionIn(COMP_HAL_MAC_API);
5200
5201 ret = hm_info->halmac_ax_ops->upd_ulru_fixtbl(
5202 hm_info->halmac_ax_apter,
5203 &ul_group->fixed_mode_group);
5204
5205 FunctionOut(COMP_HAL_MAC_API);
5206 return ret;
5207 }
5208
5209 u4Byte hal_mac_ax_update_table_ul_ru_table(RT_HAL_MAC_INFO *hm_info,
5210 struct ofdma_ul_group *ul_group)
5211 {
5212 PADAPTER adapter = hm_info->adapter;
5213 u32 ret=0;
5214 FunctionIn(COMP_HAL_MAC_API);
5215
5216 ret = hm_info->halmac_ax_ops->upd_ulru_grptbl(
5217 hm_info->halmac_ax_apter,
5218 &ul_group->ul_grp_table);
5219
5220 FunctionOut(COMP_HAL_MAC_API);
5221 return ret;
5222 }
5223
5224
5225 u4Byte hal_mac_ax_update_table_ul_drvfix(RT_HAL_MAC_INFO *hm_info,
5226 struct ofdma_ul_group *ul_group)
5227 {
5228 PADAPTER adapter = hm_info->adapter;
5229 u32 ret=0;
5230 FunctionIn(COMP_HAL_MAC_API);
5231
5232 ret = hm_info->halmac_ax_ops->upd_ul_fixinfo(
5233 hm_info->halmac_ax_apter,
5234 &ul_group->drv_fixed_info);
5235
5236 FunctionOut(COMP_HAL_MAC_API);
5237 return ret;
5238 }
5239
5240
5241 u4Byte hal_mac_ax_issue_bsrp(RT_HAL_MAC_INFO *hm_info,
5242 struct ofdma_ul_group *ul_group)
5243 {
5244 PADAPTER adapter = hm_info->adapter;
5245 u32 ret=0;
5246 FunctionIn(COMP_HAL_MAC_API);
5247
5248 ret = hm_info->halmac_ax_ops->upd_ul_fixinfo(
5249 hm_info->halmac_ax_apter,
5250 &ul_group->drv_fixed_info
5251 );
5252
5253 FunctionOut(COMP_HAL_MAC_API);
5254 return ret;
5255 }
5256
5257
5258 u4Byte hal_mac_ax_update_ru_sta(RT_HAL_MAC_INFO *hm_info,
5259 u8 *ru_sta_info)
5260 {
5261 /* upd_rusta_info */
5262 struct mac_ax_bb_stainfo *bb_stainfo = (struct mac_ax_bb_stainfo *)ru_sta_info;
5263
5264 hm_info->halmac_ax_ops->upd_rusta_info(
5265 hm_info->halmac_ax_apter,
5266 bb_stainfo
5267 );
5268 return 0;
5269 }
5270
5271 u4Byte hal_mac_ax_update_ba_info_table(RT_HAL_MAC_INFO *hm_info,
5272 u8 ba_info)
5273 {
5274 /* upd_ba_infotbl */
5275 struct mac_ax_ba_infotbl *ba_info_tbl = (struct mac_ax_ba_infotbl *)ba_info;
5276
5277 hm_info->halmac_ax_ops->upd_ba_infotbl(
5278 hm_info->halmac_ax_apter,
5279 ba_info_tbl
5280 );
5281
5282 return 0;
5283 }
5284
5285 u4Byte hal_mac_ax_Test_H2C(RT_HAL_MAC_INFO *hm_info,
5286 u32 length, u8 Burst)
5287 {
5288
5289 u32 ret =0;
5290 FunctionIn(COMP_HAL_MAC_API);
5291 ret = hm_info->halmac_ax_ops->fwcmd_lb(
5292 hm_info->halmac_ax_apter,
5293 length,
5294 Burst
5295 );
5296
5297
5298 FunctionOut(COMP_HAL_MAC_API);
5299
5300 return ret;
5301 }
5302
5303 u4Byte hal_mac_ax_compare_h2c_c2h(RT_HAL_MAC_INFO *hm_info,
5304 u8 *buf, u32 len)
5305 {
5306 u32 ret=0;
5307 FunctionIn(COMP_HAL_MAC_API);
5308 ret = hm_info->halmac_ax_ops->process_c2h(
5309 hm_info->halmac_ax_apter,
5310 buf,
5311 len
5312 );
5313 FunctionOut(COMP_HAL_MAC_API);
5314 return ret;
5315 }
5316 #endif
5317 //====================================================================
5318
5319 /*
5320 * halmac wrapper API for hal and proto type is at hal_api_mac.h
5321 * Efuse part.
5322 */
5323 enum rtw_hal_status
rtw_hal_mac_get_log_efuse_size(struct rtw_hal_com_t * hal_com,u32 * val,bool is_limited)5324 rtw_hal_mac_get_log_efuse_size(struct rtw_hal_com_t *hal_com, u32 *val,
5325 bool is_limited)
5326 {
5327 struct hal_info_t *hal_info = hal_com->hal_priv;
5328 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5329 if(is_limited == true) {
5330 if(mac->ops->get_hw_value(mac,
5331 MAC_AX_HW_GET_LIMIT_LOG_EFUSE_SIZE, val) != MACSUCCESS){
5332 PHL_ERR("%s: Get limited logical efuse size fail!\n",
5333 __FUNCTION__);
5334 return RTW_HAL_STATUS_FAILURE;
5335 }
5336 }
5337 else {
5338 if(mac->ops->get_hw_value(mac,
5339 MAC_AX_HW_GET_LOGICAL_EFUSE_SIZE, val) != MACSUCCESS){
5340 PHL_ERR("%s: Get logical efuse size fail!\n", __FUNCTION__);
5341 return RTW_HAL_STATUS_FAILURE;
5342 }
5343 }
5344 PHL_INFO("%s: Logical efuse size = %d!\n", __FUNCTION__, *val);
5345
5346 return RTW_HAL_STATUS_SUCCESS;
5347 }
5348
5349 enum rtw_hal_status
rtw_hal_mac_read_log_efuse_map(struct rtw_hal_com_t * hal_com,u8 * map,bool is_limited)5350 rtw_hal_mac_read_log_efuse_map(struct rtw_hal_com_t *hal_com, u8 *map,
5351 bool is_limited)
5352 {
5353 struct hal_info_t *hal_info = hal_com->hal_priv;
5354 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5355
5356 if (mac->ops->dump_log_efuse(mac,
5357 MAC_AX_EFUSE_PARSER_MAP,
5358 #ifdef RTW_WKARD_EFUSE_OPERATION
5359 MAC_AX_EFUSE_R_DRV,
5360 #else
5361 MAC_AX_EFUSE_R_AUTO,
5362 #endif
5363 map,
5364 is_limited
5365 ) != MACSUCCESS) {
5366 PHL_INFO("%s: Dump logical efuse fail!\n", __FUNCTION__);
5367 return RTW_HAL_STATUS_FAILURE;
5368 }
5369
5370 PHL_INFO("%s: Dump logical efuse ok!\n", __FUNCTION__);
5371 return RTW_HAL_STATUS_SUCCESS;
5372 }
5373
5374 /*
5375 * HALMAC PG EFUSE API put version length at the tail of map/mask buffer
5376 */
5377
5378 enum rtw_hal_status
rtw_hal_mac_write_log_efuse_map(struct rtw_hal_com_t * hal_com,u8 * map,u32 map_size,u8 * mask,u32 mask_size,u8 * map_version,u8 * mask_version,u8 version_length,u8 part,bool is_limited)5379 rtw_hal_mac_write_log_efuse_map(struct rtw_hal_com_t *hal_com,
5380 u8 *map,
5381 u32 map_size,
5382 u8 *mask,
5383 u32 mask_size,
5384 u8 *map_version,
5385 u8 *mask_version,
5386 u8 version_length,
5387 u8 part,
5388 bool is_limited)
5389 {
5390 struct hal_info_t *hal_info = hal_com->hal_priv;
5391 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5392 struct mac_ax_pg_efuse_info info;
5393 enum rtw_hal_status status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
5394 u8 *tmp_map = NULL;
5395 u8 *tmp_mask = NULL;
5396
5397 tmp_map = _os_mem_alloc(hal_com->drv_priv, (map_size + version_length));
5398 if(tmp_map == NULL) {
5399 PHL_WARN("%s: Allocate pg map buffer fail!\n", __FUNCTION__);
5400 status = RTW_HAL_STATUS_RESOURCE;
5401 goto err_mem_tmp_map;
5402 }
5403
5404 tmp_mask = _os_mem_alloc(hal_com->drv_priv, (mask_size + version_length));
5405 if(tmp_mask == NULL) {
5406 PHL_WARN("%s: Allocate pg mask buffer fail!\n", __FUNCTION__);
5407 status = RTW_HAL_STATUS_RESOURCE;
5408 goto err_mem_tmp_mask;
5409 }
5410
5411 /* Copy efuse map and map version to tmp_map buffer */
5412 _os_mem_cpy(hal_com->drv_priv, tmp_map, map, map_size);
5413 _os_mem_cpy(hal_com->drv_priv, tmp_map+map_size, map_version,
5414 version_length);
5415 /* Copy efuse mask and mask version to tmp_mask buffer */
5416 _os_mem_cpy(hal_com->drv_priv, tmp_mask, mask, mask_size);
5417 _os_mem_cpy(hal_com->drv_priv, tmp_mask+mask_size, mask_version,
5418 version_length);
5419 #if 0 /* For debug usage */
5420 debug_dump_data(map, (u16)map_size, "logical map:");
5421 debug_dump_data(map_version, version_length, "logical map version:");
5422 debug_dump_data(mask, (u16)mask_size, "mask:");
5423 debug_dump_data(mask_version, version_length, "mask version:");
5424 debug_dump_data(tmp_map, (u16)(map_size + version_length), "tmp_map:");
5425 debug_dump_data(tmp_mask, (u16)(mask_size + version_length), "tmp_mask:");
5426 #endif
5427 info.efuse_map = tmp_map;
5428 info.efuse_map_size = map_size;
5429 info.efuse_mask = tmp_mask;
5430 info.efuse_mask_size= mask_size;
5431
5432 if (mac->ops->pg_efuse_by_map(mac,
5433 &info,
5434 MAC_AX_EFUSE_R_DRV,
5435 part,
5436 is_limited) != MACSUCCESS) {
5437 PHL_INFO("%s: PG Fail!\n", __FUNCTION__);
5438 status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
5439 }
5440 else {
5441 PHL_INFO("%s: PG ok!\n", __FUNCTION__);
5442 status = RTW_HAL_STATUS_SUCCESS;
5443 }
5444 _os_mem_free(hal_com->drv_priv, tmp_map, (map_size + version_length));
5445 _os_mem_free(hal_com->drv_priv, tmp_mask, (mask_size + version_length));
5446
5447 return status;
5448
5449 err_mem_tmp_mask:
5450 _os_mem_free(hal_com->drv_priv, tmp_map, (map_size + version_length));
5451
5452 err_mem_tmp_map:
5453
5454 return status;
5455 }
5456
5457
5458 enum rtw_hal_status
rtw_hal_mac_read_hidden_rpt(struct rtw_hal_com_t * hal_com)5459 rtw_hal_mac_read_hidden_rpt(struct rtw_hal_com_t *hal_com)
5460 {
5461
5462 struct hal_info_t *hal_info = hal_com->hal_priv;
5463 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5464 struct mac_defeature_value rpt;
5465 u32 err;
5466
5467 err = mac->ops->read_hidden_rpt(mac, &rpt);
5468 if (err != MACSUCCESS) {
5469 PHL_TRACE(COMP_PHL_TRIG, _PHL_INFO_, "err=0x%x\n", err);
5470 return RTW_HAL_STATUS_FAILURE;
5471 }
5472
5473 if (rpt.tx_spatial_stream != 7 && rpt.tx_spatial_stream > 0) {
5474 hal_com->phy_hw_cap[0].tx_num = rpt.tx_spatial_stream;
5475 hal_com->phy_hw_cap[1].tx_num = rpt.tx_spatial_stream;
5476 hal_com->rfpath_tx_num = rpt.tx_spatial_stream;
5477 }
5478 if (rpt.rx_spatial_stream != 7 && rpt.rx_spatial_stream > 0) {
5479 hal_com->phy_hw_cap[0].rx_num = rpt.rx_spatial_stream;
5480 hal_com->phy_hw_cap[1].rx_num = rpt.rx_spatial_stream;
5481 hal_com->rfpath_rx_num = rpt.rx_spatial_stream;
5482 }
5483 if (rpt.hw_special_type > EFUSE_HW_STYPE_NONE &&
5484 rpt.hw_special_type < EFUSE_HW_STYPE_GENERAL)
5485 hal_com->dev_hw_cap.hw_stype_cap = rpt.hw_special_type;
5486
5487 if (rpt.wl_func_support > EFUSE_WL_FUNC_NONE &&
5488 rpt.wl_func_support < EFUSE_WL_FUNC_GENERAL)
5489 hal_com->dev_hw_cap.wl_func_cap = rpt.wl_func_support;
5490
5491 hal_com->uuid = rpt.uuid;
5492
5493 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden tx=%d hidden rx=%d\n",
5494 rpt.tx_spatial_stream, rpt.rx_spatial_stream);
5495 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden bw=%d\n", rpt.bandwidth);
5496 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden protocol = %d\n",
5497 rpt.protocol_80211);
5498 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden nic=%d\n", rpt.NIC_router);
5499 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden hw special type=%d\n",
5500 rpt.hw_special_type);
5501 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden wl func=%d\n",
5502 rpt.wl_func_support);
5503 PHL_INFO("%s\n", __FUNCTION__);
5504 return RTW_HAL_STATUS_SUCCESS;
5505 }
5506
5507
5508 enum rtw_hal_status
rtw_hal_mac_check_efuse_autoload(struct rtw_hal_com_t * hal_com,u8 * autoload)5509 rtw_hal_mac_check_efuse_autoload(struct rtw_hal_com_t *hal_com, u8 *autoload)
5510 {
5511 struct hal_info_t *hal_info = hal_com->hal_priv;
5512 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5513
5514 if (mac->ops->check_efuse_autoload(mac, autoload) != MACSUCCESS)
5515 return RTW_HAL_STATUS_FAILURE;
5516
5517 if(*autoload == true)
5518 PHL_INFO("%s: efuse auto load SUCCESS!\n", __FUNCTION__);
5519 else
5520 PHL_INFO("%s: efuse auto load FAIL!\n", __FUNCTION__);
5521
5522 return RTW_HAL_STATUS_SUCCESS;
5523 }
5524
5525 enum rtw_hal_status
rtw_hal_mac_get_efuse_avl(struct rtw_hal_com_t * hal_com,u32 * val)5526 rtw_hal_mac_get_efuse_avl(struct rtw_hal_com_t *hal_com, u32 *val)
5527 {
5528 struct hal_info_t *hal_info = hal_com->hal_priv;
5529 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5530
5531 if (mac->ops->get_efuse_avl_size(mac, val) != MACSUCCESS)
5532 return RTW_HAL_STATUS_FAILURE;
5533
5534 PHL_INFO("%s\n", __FUNCTION__);
5535 return RTW_HAL_STATUS_SUCCESS;
5536 }
5537
5538 enum rtw_hal_status
rtw_hal_mac_get_efuse_size(struct rtw_hal_com_t * hal_com,u32 * val)5539 rtw_hal_mac_get_efuse_size(struct rtw_hal_com_t *hal_com, u32 *val)
5540 {
5541 struct hal_info_t *hal_info = hal_com->hal_priv;
5542 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5543
5544 if (mac->ops->get_hw_value(mac,
5545 MAC_AX_HW_GET_EFUSE_SIZE, val) != MACSUCCESS){
5546 PHL_ERR("%s: Get efuse size fail!\n", __FUNCTION__);
5547 return RTW_HAL_STATUS_FAILURE;
5548 }
5549 PHL_INFO("%s: Efuse size = %d!\n", __FUNCTION__, *val);
5550
5551 return RTW_HAL_STATUS_SUCCESS;
5552 }
5553
5554 enum rtw_hal_status
rtw_hal_mac_get_efuse_mask_size(struct rtw_hal_com_t * hal_com,u32 * val,bool is_limited)5555 rtw_hal_mac_get_efuse_mask_size(struct rtw_hal_com_t *hal_com, u32 *val,
5556 bool is_limited)
5557 {
5558 struct hal_info_t *hal_info = hal_com->hal_priv;
5559 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5560
5561 if(is_limited == true) {
5562 if(mac->ops->get_hw_value(mac,
5563 MAC_AX_HW_GET_LIMIT_EFUSE_MASK_SIZE, val) != MACSUCCESS)
5564 return RTW_HAL_STATUS_FAILURE;
5565 }
5566 else {
5567 if(mac->ops->get_hw_value(mac,
5568 MAC_AX_HW_GET_EFUSE_MASK_SIZE, val) != MACSUCCESS)
5569 return RTW_HAL_STATUS_FAILURE;
5570 }
5571
5572 PHL_INFO("%s: efuse mask size = %d\n", __FUNCTION__, *val);
5573 return RTW_HAL_STATUS_SUCCESS;
5574 }
5575
5576 enum rtw_hal_status
rtw_hal_mac_get_efuse_info(struct rtw_hal_com_t * hal_com,u8 * efuse_map,enum rtw_efuse_info info_type,void * value,u8 size,u8 map_valid)5577 rtw_hal_mac_get_efuse_info(struct rtw_hal_com_t *hal_com,
5578 u8 *efuse_map, enum rtw_efuse_info info_type, void *value,
5579 u8 size, u8 map_valid)
5580 {
5581 struct hal_info_t *hal_info = hal_com->hal_priv;
5582 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5583
5584 PHL_INFO("%s\n", __FUNCTION__);
5585
5586 if (mac->ops->get_efuse_info(mac, efuse_map, info_type, value, size,
5587 &map_valid) != MACSUCCESS)
5588 return RTW_HAL_STATUS_FAILURE;
5589 return RTW_HAL_STATUS_SUCCESS;
5590 }
5591
5592 enum rtw_hal_status
rtw_hal_mac_read_phy_efuse(struct rtw_hal_com_t * hal_com,u32 addr,u32 size,u8 * value)5593 rtw_hal_mac_read_phy_efuse(struct rtw_hal_com_t *hal_com,
5594 u32 addr, u32 size, u8 *value)
5595 {
5596 struct hal_info_t *hal_info = hal_com->hal_priv;
5597 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5598
5599 PHL_INFO("%s\n", __FUNCTION__);
5600
5601 if (mac->ops->read_efuse(mac, addr, size, value,
5602 MAC_AX_EFUSE_BANK_WIFI) != MACSUCCESS)
5603 return RTW_HAL_STATUS_FAILURE;
5604 return RTW_HAL_STATUS_SUCCESS;
5605 }
5606
5607 enum rtw_hal_status
rtw_hal_mac_read_bt_phy_efuse(struct rtw_hal_com_t * hal_com,u32 addr,u32 size,u8 * value)5608 rtw_hal_mac_read_bt_phy_efuse(struct rtw_hal_com_t *hal_com,
5609 u32 addr, u32 size, u8 *value)
5610 {
5611 struct hal_info_t *hal_info = hal_com->hal_priv;
5612 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5613
5614 PHL_INFO("%s\n", __FUNCTION__);
5615
5616 if (mac->ops->read_efuse(mac, addr, size, value,
5617 MAC_AX_EFUSE_BANK_BT) != MACSUCCESS)
5618 return RTW_HAL_STATUS_FAILURE;
5619 return RTW_HAL_STATUS_SUCCESS;
5620 }
5621
rtw_hal_mac_write_msk_pwr_reg(struct rtw_hal_com_t * hal_com,u8 band,u32 offset,u32 mask,u32 val)5622 u32 rtw_hal_mac_write_msk_pwr_reg(
5623 struct rtw_hal_com_t *hal_com, u8 band, u32 offset, u32 mask, u32 val)
5624 {
5625 struct hal_info_t *hal = hal_com->hal_priv;
5626 struct mac_ax_adapter *mac = hal_to_mac(hal);
5627 struct mac_ax_ops *ops = mac->ops;
5628 u32 result = 0;
5629
5630 result = ops->write_msk_pwr_reg(mac, band, offset, mask, val);
5631
5632 if (result != MACSUCCESS)
5633 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_,
5634 "Write power register failure, status = %d\n", result);
5635
5636 return result;
5637 }
5638
rtw_hal_mac_set_pwr_reg(struct rtw_hal_com_t * hal_com,u8 band,u32 offset,u32 val)5639 u32 rtw_hal_mac_set_pwr_reg(struct rtw_hal_com_t *hal_com, u8 band, u32 offset, u32 val){
5640
5641 struct hal_info_t *hal = hal_com->hal_priv;
5642 struct mac_ax_adapter *mac = hal_to_mac(hal);
5643 struct mac_ax_ops *ops = mac->ops;
5644 u32 result = 0;
5645
5646 result = ops->write_pwr_reg(mac, band, offset, val);
5647
5648 if (result != MACSUCCESS)
5649 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set power register failure, status = %d\n", result);
5650
5651 return result;
5652 }
5653
rtw_hal_mac_get_pwr_reg(struct rtw_hal_com_t * hal_com,u8 band,u32 offset,u32 * val)5654 u32 rtw_hal_mac_get_pwr_reg(struct rtw_hal_com_t *hal_com, u8 band, u32 offset, u32 *val){
5655 struct hal_info_t *hal = hal_com->hal_priv;
5656 struct mac_ax_adapter *mac = hal_to_mac(hal);
5657 struct mac_ax_ops *ops = mac->ops;
5658 u32 result = 0;
5659
5660 result = ops->read_pwr_reg(mac, band, offset, val);
5661
5662 if (result != MACSUCCESS)
5663 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Get power register failure, status = %d\n", result);
5664
5665 return result;
5666 }
5667
5668 enum rtw_hal_status
rtw_hal_mac_get_xcap(struct rtw_hal_com_t * hal_com,u8 sc_xo,u32 * value)5669 rtw_hal_mac_get_xcap(struct rtw_hal_com_t *hal_com, u8 sc_xo, u32 *value){
5670 struct hal_info_t *hal_info = hal_com->hal_priv;
5671 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5672 struct mac_ax_ops *ops = mac->ops;
5673 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5674
5675 ret = ops->read_xcap_reg(mac, sc_xo, value);
5676
5677 if (ret != MACSUCCESS)
5678 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Get xacp failure, status = %d\n", ret);
5679
5680 return ret;
5681 }
5682
5683 enum rtw_hal_status
rtw_hal_mac_set_xcap(struct rtw_hal_com_t * hal_com,u8 sc_xo,u32 value)5684 rtw_hal_mac_set_xcap(struct rtw_hal_com_t *hal_com, u8 sc_xo, u32 value){
5685 struct hal_info_t *hal_info = hal_com->hal_priv;
5686 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5687 struct mac_ax_ops *ops = mac->ops;
5688 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5689
5690 ret = ops->write_xcap_reg(mac, sc_xo, value);
5691
5692 if (ret != MACSUCCESS)
5693 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set xacp failure, status = %d\n", ret);
5694
5695 return ret;
5696 }
5697
5698 enum rtw_hal_status
rtw_hal_mac_get_xsi(struct rtw_hal_com_t * hal_com,u8 offset,u8 * val)5699 rtw_hal_mac_get_xsi(struct rtw_hal_com_t *hal_com, u8 offset, u8* val)
5700 {
5701 struct hal_info_t *hal_info = hal_com->hal_priv;
5702 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5703
5704 /* Because mac si function is not support mac ops*/
5705 /* we call mac si function temporarily until mac team feedback.*/
5706 if (mac_read_xtal_si(mac, offset, val) != MACSUCCESS) {
5707 PHL_INFO("Get xsi failure, status = %s\n", __FUNCTION__);
5708 return RTW_HAL_STATUS_FAILURE;
5709 }
5710
5711 PHL_INFO("%s\n", __FUNCTION__);
5712 return RTW_HAL_STATUS_SUCCESS;
5713 }
5714
5715 enum rtw_hal_status
rtw_hal_mac_set_xsi(struct rtw_hal_com_t * hal_com,u8 offset,u8 val)5716 rtw_hal_mac_set_xsi(struct rtw_hal_com_t *hal_com, u8 offset, u8 val)
5717 {
5718 struct hal_info_t *hal_info = hal_com->hal_priv;
5719 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5720
5721 /* Because mac si function is not support mac ops*/
5722 /* we call mac si function temporarily until mac team feedback.*/
5723 if (mac_write_xtal_si(mac, offset, val, 0xff) != MACSUCCESS) {
5724 PHL_INFO("Set xsi failure, status = %s\n", __FUNCTION__);
5725 return RTW_HAL_STATUS_FAILURE;
5726 }
5727
5728 PHL_INFO("%s\n", __FUNCTION__);
5729 return RTW_HAL_STATUS_SUCCESS;
5730 }
5731
5732
5733 enum rtw_hal_status
rtw_hal_mac_fw_dbg_dump(struct hal_info_t * hal_info)5734 rtw_hal_mac_fw_dbg_dump(struct hal_info_t *hal_info)
5735 {
5736 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5737 u8 *buffer = NULL;
5738 u16 bufSize = FW_PLE_SIZE;
5739 struct mac_ax_fwdbg_en en;
5740 u32 mac_err = 0;
5741
5742 en.status_dbg = 1;
5743 en.ps_dbg = 1;
5744 en.rsv_ple_dbg = 0;
5745
5746 mac_err = mac->ops->fw_dbg_dump(mac, &buffer, &en);
5747 if (mac_err != MACSUCCESS) {
5748 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
5749 return RTW_HAL_STATUS_FAILURE;
5750 }
5751
5752 if (en.rsv_ple_dbg && buffer) {
5753 /*fw buffer is 2048, but Windows DbgPrint only 512 Bytes, so we split buffer to 4 segments*/
5754 if (buffer != NULL) {
5755 PHL_PRINT("=======================\n");
5756 PHL_PRINT("Start to dump fw rsvd ple:\n\n");
5757 _hal_fw_dbg_dump(hal_info, buffer, bufSize);
5758 PHL_PRINT("\n=======================\n");
5759 }
5760 }
5761 if (buffer != NULL)
5762 _os_mem_free(hal_info->hal_com->drv_priv, buffer, bufSize);
5763
5764 return RTW_HAL_STATUS_SUCCESS;
5765 }
5766
5767 enum rtw_hal_status
rtw_hal_mac_ps_notify_wake(struct hal_info_t * hal_info)5768 rtw_hal_mac_ps_notify_wake(struct hal_info_t *hal_info)
5769 {
5770 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5771
5772 if (mac->ops->ps_notify_wake(mac) == MACSUCCESS) {
5773 return RTW_HAL_STATUS_SUCCESS;
5774 } else {
5775 PHL_WARN("%s: notify wake fail!\n", __FUNCTION__);
5776 return RTW_HAL_STATUS_FAILURE;
5777 }
5778 }
5779
5780 enum rtw_hal_status
rtw_hal_mac_req_pwr_state(struct hal_info_t * hal_info,u8 pwr_state)5781 rtw_hal_mac_req_pwr_state(struct hal_info_t *hal_info, u8 pwr_state)
5782 {
5783 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5784
5785 if(mac->ops->ps_pwr_state(mac, MAC_AX_PWR_STATE_ACT_REQ, pwr_state)
5786 == MACSUCCESS)
5787 return RTW_HAL_STATUS_SUCCESS;
5788 else
5789 return RTW_HAL_STATUS_FAILURE;
5790 }
5791
5792 enum rtw_hal_status
rtw_hal_mac_chk_pwr_state(struct hal_info_t * hal_info,u8 pwr_state,u32 * mac_sts)5793 rtw_hal_mac_chk_pwr_state(struct hal_info_t *hal_info, u8 pwr_state, u32 *mac_sts)
5794 {
5795 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5796
5797 *mac_sts = mac->ops->ps_pwr_state(mac, MAC_AX_PWR_STATE_ACT_CHK, pwr_state);
5798 if(*mac_sts == MACSUCCESS)
5799 return RTW_HAL_STATUS_SUCCESS;
5800 else
5801 return RTW_HAL_STATUS_FAILURE;
5802 }
5803
5804 enum rtw_hal_status
rtw_hal_mac_ips_cfg(struct hal_info_t * hal_info,u16 macid,bool enable)5805 rtw_hal_mac_ips_cfg(struct hal_info_t *hal_info, u16 macid, bool enable)
5806 {
5807 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5808
5809 if (mac->ops->cfg_ips(mac, (u8)macid, enable) == MACSUCCESS)
5810 return RTW_HAL_STATUS_SUCCESS;
5811 else
5812 return RTW_HAL_STATUS_FAILURE;
5813 }
5814
5815 enum rtw_hal_status
rtw_hal_mac_ips_chk_leave(struct hal_info_t * hal_info,u16 macid)5816 rtw_hal_mac_ips_chk_leave(struct hal_info_t *hal_info, u16 macid)
5817 {
5818 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5819
5820 if (mac->ops->chk_leave_ips(mac, (u8)macid) == MACSUCCESS)
5821 return RTW_HAL_STATUS_SUCCESS;
5822 else
5823 return RTW_HAL_STATUS_FAILURE;
5824 }
5825
5826 enum rtw_hal_status
rtw_hal_mac_lps_cfg(struct hal_info_t * hal_info,struct rtw_hal_lps_info * lps_info)5827 rtw_hal_mac_lps_cfg(struct hal_info_t *hal_info,
5828 struct rtw_hal_lps_info *lps_info)
5829 {
5830 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5831 enum mac_ax_ps_mode ax_ps_mode;
5832 struct mac_ax_lps_info ax_lps_info;
5833
5834 if (lps_info->en) {
5835 ax_ps_mode = MAC_AX_PS_MODE_LEGACY;
5836 } else {
5837 ax_ps_mode = MAC_AX_PS_MODE_ACTIVE;
5838 }
5839
5840 ax_lps_info.listen_bcn_mode = lps_info->listen_bcn_mode;
5841 ax_lps_info.awake_interval = lps_info->awake_interval;
5842 ax_lps_info.smart_ps_mode = lps_info->smart_ps_mode;
5843
5844 if (mac->ops->cfg_lps(mac, (u8)lps_info->macid, ax_ps_mode,
5845 &ax_lps_info) == MACSUCCESS)
5846 return RTW_HAL_STATUS_SUCCESS;
5847 else
5848 return RTW_HAL_STATUS_FAILURE;
5849 }
5850
5851 enum rtw_hal_status
rtw_hal_mac_lps_chk_leave(struct hal_info_t * hal_info,u16 macid,u32 * mac_sts)5852 rtw_hal_mac_lps_chk_leave(struct hal_info_t *hal_info, u16 macid, u32 *mac_sts)
5853 {
5854 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5855
5856 *mac_sts = mac->ops->chk_leave_lps(mac, (u8)macid);
5857 if(*mac_sts == MACSUCCESS)
5858 return RTW_HAL_STATUS_SUCCESS;
5859 else
5860 return RTW_HAL_STATUS_FAILURE;
5861 }
5862
5863 enum rtw_hal_status
rtw_hal_mac_lps_chk_access(struct hal_info_t * hal_info,u32 offset)5864 rtw_hal_mac_lps_chk_access(struct hal_info_t *hal_info, u32 offset)
5865 {
5866 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5867
5868 if(mac->ops->io_chk_access(mac, offset) == MACSUCCESS)
5869 return RTW_HAL_STATUS_SUCCESS;
5870 else
5871 return RTW_HAL_STATUS_FAILURE;
5872 }
5873
5874 enum rtw_hal_status
rtw_hal_mac_get_rx_cnt(struct hal_info_t * hal_info,u8 cur_phy_idx,u8 type_idx,u32 * ret_value)5875 rtw_hal_mac_get_rx_cnt(struct hal_info_t *hal_info, u8 cur_phy_idx, u8 type_idx, u32 *ret_value){
5876 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5877 struct mac_ax_ops *ops = mac->ops;
5878 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5879
5880 struct mac_ax_rx_cnt rx_cnt;
5881 u16 rx_cnt_buff[MAC_AX_RX_PPDU_MAX];
5882 u32 rx_cnt_total=0;
5883 u16 ppdu_idx;
5884
5885 rx_cnt.type = type_idx;
5886 rx_cnt.op = MAC_AX_RXCNT_R;
5887 rx_cnt.buf = rx_cnt_buff;
5888 rx_cnt.band = cur_phy_idx;
5889
5890 ret = ops->rx_cnt(mac, &rx_cnt);
5891
5892 for(ppdu_idx=0;ppdu_idx<MAC_AX_RX_PPDU_MAX;ppdu_idx++)
5893 {
5894 rx_cnt_total+=rx_cnt_buff[ppdu_idx];
5895 }
5896
5897 *ret_value = rx_cnt_total;
5898
5899 if (ret != MACSUCCESS){
5900 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "mac get rx counter fail, status=%d\n",ret);
5901 }
5902
5903 return ret;
5904 }
5905
5906 enum rtw_hal_status
rtw_hal_mac_set_reset_rx_cnt(struct hal_info_t * hal_info,u8 cur_phy_idx)5907 rtw_hal_mac_set_reset_rx_cnt(struct hal_info_t *hal_info, u8 cur_phy_idx)
5908 {
5909 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5910 struct mac_ax_ops *ops = mac->ops;
5911 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5912
5913 struct mac_ax_rx_cnt rx_cnt;
5914 u16 rx_cnt_buff[MAC_AX_RX_PPDU_MAX];
5915
5916 rx_cnt.type = MAC_AX_RX_IDX;
5917 rx_cnt.op = MAC_AX_RXCNT_RST_ALL;
5918 rx_cnt.buf = rx_cnt_buff;
5919 rx_cnt.band = cur_phy_idx;
5920
5921 ret = ops->rx_cnt(mac, &rx_cnt);
5922
5923 if (ret != MACSUCCESS){
5924 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "mac reset rx cnt fail, status=%d\n",ret);
5925 }
5926
5927 return ret;
5928 }
5929
5930 enum rtw_hal_status
rtw_hal_mac_tx_idle_poll(struct rtw_hal_com_t * hal_com,u8 band_idx)5931 rtw_hal_mac_tx_idle_poll(struct rtw_hal_com_t *hal_com, u8 band_idx)
5932 {
5933 struct hal_info_t *hal = hal_com->hal_priv;
5934 struct mac_ax_adapter *mac = hal_to_mac(hal);
5935 struct mac_ax_tx_idle_poll_cfg cfg = {0};
5936 u32 err = 0;
5937
5938
5939 cfg.sel = MAC_AX_TX_IDLE_POLL_SEL_BAND;
5940 cfg.band = band_idx;
5941 err = mac->ops->tx_idle_poll(mac, &cfg);
5942 if (err != MACSUCCESS) {
5943 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_,
5944 "Polling tx idle failure(%d)!\n", err);
5945 return RTW_HAL_STATUS_TIMEOUT;
5946 }
5947
5948 return RTW_HAL_STATUS_SUCCESS;
5949 }
5950
5951 enum rtw_sch_txen_cfg {
5952 RTW_TXEN_BE0 = 1 << 0,
5953 RTW_TXEN_BK0 = 1 << 1,
5954 RTW_TXEN_VI0 = 1 << 2,
5955 RTW_TXEN_VO0 = 1 << 3,
5956 RTW_TXEN_BE1 = 1 << 4,
5957 RTW_TXEN_BK1 = 1 << 5,
5958 RTW_TXEN_VI1 = 1 << 6,
5959 RTW_TXEN_VO1 = 1 << 7,
5960 RTW_TXEN_MG0 = 1 << 8,
5961 RTW_TXEN_MG1 = 1 << 9,
5962 RTW_TXEN_MG2 = 1 << 10,
5963 RTW_TXEN_HI = 1 << 11,
5964 RTW_TXEN_BCN = 1 << 12,
5965 RTW_TXEN_UL = 1 << 13,
5966 RTW_TXEN_TWT0 = 1 << 14,
5967 RTW_TXEN_TWT1 = 1 << 15,
5968 RTW_TXEN_DRV_MASK = 0x19FF,
5969 RTW_TXEN_ALL = 0xFFFF,
5970 };
5971
5972 enum rtw_hal_status
rtw_hal_mac_set_sch_tx_en(struct rtw_hal_com_t * hal_com,u8 band_idx,u16 tx_en,u16 tx_en_mask)5973 rtw_hal_mac_set_sch_tx_en(struct rtw_hal_com_t *hal_com, u8 band_idx,
5974 u16 tx_en, u16 tx_en_mask)
5975 {
5976 struct hal_info_t *hal = hal_com->hal_priv;
5977 struct mac_ax_adapter *mac = hal_to_mac(hal);
5978 struct mac_ax_ops *ops = mac->ops;
5979 struct mac_ax_sch_tx_en_cfg cfg;
5980 enum rtw_hal_status ret;
5981 u32 result = 0;
5982
5983 ret = RTW_HAL_STATUS_SUCCESS;
5984 cfg.band = band_idx;
5985
5986 cfg.tx_en.be0 = ((tx_en & RTW_TXEN_BE0) ? 1 : 0);
5987 cfg.tx_en.bk0 = ((tx_en & RTW_TXEN_BK0) ? 1 : 0);
5988 cfg.tx_en.vi0 = ((tx_en & RTW_TXEN_VI0) ? 1 : 0);
5989 cfg.tx_en.vo0 = ((tx_en & RTW_TXEN_VO0) ? 1 : 0);
5990 cfg.tx_en.be1 = ((tx_en & RTW_TXEN_BE1) ? 1 : 0);
5991 cfg.tx_en.bk1 = ((tx_en & RTW_TXEN_BK1) ? 1 : 0);
5992 cfg.tx_en.vi1 = ((tx_en & RTW_TXEN_VI1) ? 1 : 0);
5993 cfg.tx_en.vo1 = ((tx_en & RTW_TXEN_VO1) ? 1 : 0);
5994 cfg.tx_en.mg0 = ((tx_en & RTW_TXEN_MG0) ? 1 : 0);
5995 cfg.tx_en.mg1 = ((tx_en & RTW_TXEN_MG1) ? 1 : 0);
5996 cfg.tx_en.mg2 = ((tx_en & RTW_TXEN_MG2) ? 1 : 0);
5997 cfg.tx_en.hi = ((tx_en & RTW_TXEN_HI) ? 1 : 0);
5998 cfg.tx_en.bcn = ((tx_en & RTW_TXEN_BCN) ? 1 : 0);
5999 cfg.tx_en.ul = ((tx_en & RTW_TXEN_UL) ? 1 : 0);
6000 cfg.tx_en.twt0 = ((tx_en & RTW_TXEN_TWT0) ? 1 : 0);
6001 cfg.tx_en.twt1 = ((tx_en & RTW_TXEN_TWT1) ? 1 : 0);
6002
6003 cfg.tx_en_mask.be0 = ((tx_en_mask & RTW_TXEN_BE0) ? 1 : 0);
6004 cfg.tx_en_mask.bk0 = ((tx_en_mask & RTW_TXEN_BK0) ? 1 : 0);
6005 cfg.tx_en_mask.vi0 = ((tx_en_mask & RTW_TXEN_VI0) ? 1 : 0);
6006 cfg.tx_en_mask.vo0 = ((tx_en_mask & RTW_TXEN_VO0) ? 1 : 0);
6007 cfg.tx_en_mask.be1 = ((tx_en_mask & RTW_TXEN_BE1) ? 1 : 0);
6008 cfg.tx_en_mask.bk1 = ((tx_en_mask & RTW_TXEN_BK1) ? 1 : 0);
6009 cfg.tx_en_mask.vi1 = ((tx_en_mask & RTW_TXEN_VI1) ? 1 : 0);
6010 cfg.tx_en_mask.vo1 = ((tx_en_mask & RTW_TXEN_VO1) ? 1 : 0);
6011 cfg.tx_en_mask.mg0 = ((tx_en_mask & RTW_TXEN_MG0) ? 1 : 0);
6012 cfg.tx_en_mask.mg1 = ((tx_en_mask & RTW_TXEN_MG1) ? 1 : 0);
6013 cfg.tx_en_mask.mg2 = ((tx_en_mask & RTW_TXEN_MG2) ? 1 : 0);
6014 cfg.tx_en_mask.hi = ((tx_en_mask & RTW_TXEN_HI) ? 1 : 0);
6015 cfg.tx_en_mask.bcn = ((tx_en_mask & RTW_TXEN_BCN) ? 1 : 0);
6016 cfg.tx_en_mask.ul = ((tx_en_mask & RTW_TXEN_UL) ? 1 : 0);
6017 cfg.tx_en_mask.twt0 = ((tx_en_mask & RTW_TXEN_TWT0) ? 1 : 0);
6018 cfg.tx_en_mask.twt1 = ((tx_en_mask & RTW_TXEN_TWT1) ? 1 : 0);
6019
6020 result = ops->set_hw_value(mac, MAC_AX_HW_SET_SCH_TXEN_CFG, &cfg);
6021
6022 if (result != MACSUCCESS) {
6023 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set Tx pause failure, status = %d\n", result);
6024 ret = RTW_HAL_STATUS_FAILURE;
6025 }
6026
6027 return ret;
6028 }
6029
6030 enum rtw_hal_status
rtw_hal_tx_pause(struct rtw_hal_com_t * hal_com,u8 band_idx,bool tx_pause,enum tx_pause_rson rson)6031 rtw_hal_tx_pause(struct rtw_hal_com_t *hal_com,
6032 u8 band_idx, bool tx_pause, enum tx_pause_rson rson)
6033 {
6034 u16 *tx_off;
6035 enum tx_pause_rson i;
6036 u16 tx_cfg = 0;
6037 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
6038
6039
6040 tx_off = &hal_com->band[band_idx].tx_pause[rson];
6041 if (tx_pause == true) {
6042 switch (rson) {
6043 case PAUSE_RSON_NOR_SCAN:
6044 *tx_off = (u16)~RTW_TXEN_MG0;
6045 break;
6046 case PAUSE_RSON_RFK:
6047 case PAUSE_RSON_PSD:
6048 case PAUSE_RSON_DFS:
6049 case PAUSE_RSON_DBCC:
6050 case PAUSE_RSON_RESET:
6051 *tx_off = (u16)RTW_TXEN_ALL;
6052 break;
6053 default:
6054 PHL_ERR("Unknow pause reason:%d\n", rson);
6055 goto _error;
6056 }
6057 } else {
6058 *tx_off = 0;
6059 }
6060
6061 tx_off = hal_com->band[band_idx].tx_pause;
6062 for (i = 0; (i < PAUSE_RSON_MAX) && (tx_cfg != RTW_TXEN_ALL); i++)
6063 if (tx_off[i])
6064 tx_cfg |= tx_off[i];
6065 /* tx_cfg is white list, but tx_pause of struct rtw_hw_band is black list */
6066 tx_cfg = ~tx_cfg;
6067 PHL_INFO("TX %sPause - Reason(%d) for band-%u, final tx_cfg(0x%04x)\n",
6068 tx_pause?"":"Un-", rson, band_idx, tx_cfg);
6069
6070 hstatus = rtw_hal_mac_set_sch_tx_en(hal_com, band_idx,
6071 tx_cfg, RTW_TXEN_ALL);
6072 if (hstatus != RTW_HAL_STATUS_SUCCESS)
6073 goto _error;
6074
6075 if ((rson == PAUSE_RSON_RFK) && tx_pause) {
6076 hstatus = rtw_hal_mac_tx_idle_poll(hal_com, band_idx);
6077 if (hstatus != RTW_HAL_STATUS_SUCCESS)
6078 goto _error;
6079 }
6080
6081 _error:
6082 return hstatus;
6083 }
6084
6085 enum rtw_hal_status
rtw_hal_mac_set_macid_pause(struct rtw_hal_com_t * hal_com,u16 macid,bool pause)6086 rtw_hal_mac_set_macid_pause(struct rtw_hal_com_t *hal_com,
6087 u16 macid, bool pause)
6088 {
6089 struct hal_info_t *hal = hal_com->hal_priv;
6090 struct mac_ax_adapter *mac = hal_to_mac(hal);
6091 struct mac_ax_ops *ops = mac->ops;
6092 struct mac_ax_macid_pause_cfg cfg = {0};
6093 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
6094
6095 cfg.macid = (u8)macid;
6096 cfg.pause = pause;
6097
6098 PHL_INFO("%s macid:%d(%s) \n", __func__, macid, pause ? "pause":"unpause");
6099 /*TODO - MAC_AX_HW_SET_MULTI_ID_PAUSE*/
6100 if (ops->set_hw_value(mac, MAC_AX_HW_SET_ID_PAUSE, &cfg) != MACSUCCESS) {
6101 PHL_ERR("%s failed\n", __func__);
6102 hstatus = RTW_HAL_STATUS_FAILURE;
6103 }
6104
6105 return hstatus;
6106 }
6107
6108 enum rtw_hal_status
rtw_hal_mac_set_macid_grp_pause(struct rtw_hal_com_t * hal_com,u32 * macid_arr,u8 macid_arr_sz,bool pause)6109 rtw_hal_mac_set_macid_grp_pause(struct rtw_hal_com_t *hal_com,
6110 u32 *macid_arr, u8 macid_arr_sz, bool pause)
6111 {
6112 struct hal_info_t *hal = hal_com->hal_priv;
6113 struct mac_ax_adapter *mac = hal_to_mac(hal);
6114 struct mac_ax_ops *ops = mac->ops;
6115 struct mac_ax_macid_pause_grp cfg = {0};
6116 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
6117 u8 pause_grp_sz = 0, mac_grp_sz = 0, arr_idx = 0, bit_idx = 0;
6118 u32 mac_ret = MACSUCCESS;
6119
6120 /* size check */
6121 mac_grp_sz = sizeof(cfg.pause_grp) / sizeof(cfg.pause_grp[0]);
6122 pause_grp_sz = MIN(mac_grp_sz, macid_arr_sz);
6123
6124 for (arr_idx = 0; arr_idx < pause_grp_sz; arr_idx++) {
6125 for (bit_idx = 0; bit_idx < 32; bit_idx++) {
6126 if (macid_arr[arr_idx] & BIT(bit_idx)) {
6127 cfg.mask_grp[arr_idx] |= BIT(bit_idx);
6128 if (pause)
6129 cfg.pause_grp[arr_idx] |= BIT(bit_idx);
6130 else
6131 cfg.pause_grp[arr_idx] &= ~BIT(bit_idx);
6132 }
6133 }
6134 }
6135
6136 PHL_INFO("%s cfg pause_grp:0x%x,0x%x,0x%x,0x%x, mask_grp:0x%x,0x%x,0x%x,0x%x(%s)\n", __func__,
6137 cfg.pause_grp[0], cfg.pause_grp[1], cfg.pause_grp[2], cfg.pause_grp[3],
6138 cfg.mask_grp[0], cfg.mask_grp[1], cfg.mask_grp[2], cfg.mask_grp[3],
6139 pause ? "pause":"unpause");
6140
6141 mac_ret = ops->set_hw_value(mac, MAC_AX_HW_SET_MULTI_ID_PAUSE, &cfg);
6142 if (mac_ret != MACSUCCESS) {
6143 PHL_ERR("%s failed(mac ret:%d)\n", __func__, mac_ret);
6144 hstatus = RTW_HAL_STATUS_FAILURE;
6145 }
6146
6147 return hstatus;
6148 }
6149
6150 enum rtw_hal_status
rtw_hal_mac_fw_log_cfg(struct rtw_hal_com_t * hal_com,struct rtw_hal_fw_log_cfg * fl_cfg)6151 rtw_hal_mac_fw_log_cfg(struct rtw_hal_com_t *hal_com,
6152 struct rtw_hal_fw_log_cfg *fl_cfg)
6153 {
6154 struct hal_info_t *hal = hal_com->hal_priv;
6155 struct mac_ax_adapter *mac = hal_to_mac(hal);
6156 struct mac_ax_fw_log log_cfg = {0};
6157 u32 status;
6158
6159 if(mac == NULL)
6160 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
6161
6162 log_cfg.level = fl_cfg->level;
6163 log_cfg.output = fl_cfg->output;
6164 log_cfg.comp = fl_cfg->comp;
6165 log_cfg.comp_ext = fl_cfg->comp_ext;
6166
6167 PHL_PRINT("%s: level %d, output 0x%08x, comp 0x%08x, comp ext 0x%08x.\n",
6168 __func__,
6169 log_cfg.level,
6170 log_cfg.output,
6171 log_cfg.comp,
6172 log_cfg.comp_ext);
6173
6174 if(log_cfg.output == MAC_AX_FL_LV_UART)
6175 {
6176 mac->ops->pinmux_set_func(mac, MAC_AX_GPIO_UART_TX_GPIO5);
6177 mac->ops->sel_uart_tx_pin(mac, MAC_AX_UART_TX_GPIO5);
6178 mac->ops->pinmux_set_func(mac, MAC_AX_GPIO_UART_RX_GPIO6);
6179 mac->ops->sel_uart_rx_pin(mac, MAC_AX_UART_RX_GPIO6);
6180 }
6181
6182 status = mac->ops->fw_log_cfg(mac, &log_cfg);
6183 if (status != MACSUCCESS) {
6184 PHL_ERR("%s fault, status = %d.\n", __func__, status);
6185 return RTW_HAL_STATUS_FAILURE;
6186 }
6187 return RTW_HAL_STATUS_SUCCESS;
6188 }
6189
6190 u32
rtw_hal_mac_lamode_trig(struct rtw_hal_com_t * hal_com,u8 trig)6191 rtw_hal_mac_lamode_trig(struct rtw_hal_com_t *hal_com, u8 trig)
6192 {
6193 struct hal_info_t *hal_info = hal_com->hal_priv;
6194 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6195 u32 rpt = 0;
6196
6197 rpt = mac->ops->lamode_trigger(mac, trig);
6198
6199 return rpt;
6200 }
6201
6202 enum rtw_hal_status
rtw_hal_mac_lamode_cfg_buf(struct rtw_hal_com_t * hal_com,u8 buf_sel,u32 * addr_start,u32 * addr_end)6203 rtw_hal_mac_lamode_cfg_buf(struct rtw_hal_com_t *hal_com, u8 buf_sel,
6204 u32 *addr_start, u32 *addr_end)
6205 {
6206 struct hal_info_t *hal_info = hal_com->hal_priv;
6207 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6208 struct mac_ax_la_buf_param param;
6209
6210 param.la_buf_sel = buf_sel;
6211
6212 mac->ops->lamode_buf_cfg(mac, ¶m);
6213
6214 *addr_start = param.start_addr;
6215 *addr_end = param.end_addr;
6216
6217 return RTW_HAL_STATUS_SUCCESS;
6218 }
6219
6220 enum rtw_hal_status
rtw_hal_mac_lamode_cfg(struct rtw_hal_com_t * hal_com,u8 func_en,u8 restart_en,u8 timeout_en,u8 timeout_val,u8 data_loss_imr,u8 la_tgr_tu_sel,u8 tgr_time_val)6221 rtw_hal_mac_lamode_cfg(struct rtw_hal_com_t *hal_com, u8 func_en,
6222 u8 restart_en, u8 timeout_en, u8 timeout_val,
6223 u8 data_loss_imr, u8 la_tgr_tu_sel, u8 tgr_time_val)
6224 {
6225 struct hal_info_t *hal_info = hal_com->hal_priv;
6226 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6227 struct mac_ax_la_cfg cfg;
6228
6229 cfg.la_func_en = func_en;
6230 cfg.la_restart_en = restart_en;
6231 cfg.la_timeout_en = timeout_en;
6232 cfg.la_timeout_val = timeout_val;
6233 cfg.la_data_loss_imr = data_loss_imr;
6234 cfg.la_tgr_tu_sel = la_tgr_tu_sel;
6235 cfg.la_tgr_time_val = tgr_time_val;
6236
6237 mac->ops->lamode_cfg(mac, &cfg);
6238
6239 return RTW_HAL_STATUS_SUCCESS;
6240 }
6241
6242 enum rtw_hal_status
rtw_hal_mac_get_lamode_st(struct rtw_hal_com_t * hal_com,u8 * la_state,u16 * la_finish_addr,bool * la_round_up,bool * la_loss_data)6243 rtw_hal_mac_get_lamode_st(struct rtw_hal_com_t *hal_com, u8 *la_state,
6244 u16 *la_finish_addr, bool *la_round_up,
6245 bool *la_loss_data)
6246 {
6247 struct hal_info_t *hal_info = hal_com->hal_priv;
6248 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6249 struct mac_ax_la_status info;
6250
6251 info = mac->ops->get_lamode_st(mac);
6252
6253 *la_state = info.la_sw_fsmst;
6254 *la_finish_addr = info.la_buf_wptr;
6255 *la_round_up = info.la_buf_rndup_ind;
6256 *la_loss_data = info.la_data_loss;
6257
6258 return RTW_HAL_STATUS_SUCCESS;
6259 }
6260
_hal_set_dft_rxfltr(struct mac_ax_rx_fltr_ctrl_t * ctrl,struct mac_ax_rx_fltr_ctrl_t * mask)6261 static inline void _hal_set_dft_rxfltr(struct mac_ax_rx_fltr_ctrl_t *ctrl,
6262 struct mac_ax_rx_fltr_ctrl_t *mask)
6263 {
6264 /* filter packets by address */
6265 ctrl->sniffer_mode = 0;
6266 mask->sniffer_mode = 1;
6267
6268 /* check unicast */
6269 ctrl->acpt_a1_match_pkt = 1;
6270 mask->acpt_a1_match_pkt = 1;
6271 ctrl->uc_pkt_chk_cam_match = 1;
6272 mask->uc_pkt_chk_cam_match = 1;
6273
6274 /* check broadcast */
6275 ctrl->acpt_bc_pkt = 1;
6276 mask->acpt_bc_pkt = 1;
6277 ctrl->bc_pkt_chk_cam_match = 1;
6278 mask->bc_pkt_chk_cam_match = 1;
6279
6280 /* check multicast */
6281 ctrl->acpt_mc_pkt = 1;
6282 mask->acpt_mc_pkt = 1;
6283 /* black list filter */
6284 ctrl->mc_pkt_white_lst_mode = 0;
6285 mask->mc_pkt_white_lst_mode = 1;
6286
6287 /* check beacon */
6288 ctrl->bcn_chk_en = 1;
6289 mask->bcn_chk_en = 1;
6290 ctrl->bcn_chk_rule = 0; /* 2: A2&A3 match */
6291 mask->bcn_chk_rule = 0x3;
6292
6293 /* misc */
6294 ctrl->acpt_pwr_mngt_pkt = 1;
6295 mask->acpt_pwr_mngt_pkt = 1;
6296
6297 ctrl->acpt_ftm_req_pkt = 1;
6298 mask->acpt_ftm_req_pkt = 1;
6299 }
6300 /**
6301 * rtw_hal_mac_set_rxfltr_by_mode - Set rx filter option by scenario
6302 * @hal_com: pointer of struct rtw_hal_com_t
6303 * @band: 0x0: band0, 0x1: band1
6304 * @mode: scenario mode
6305 *
6306 * Set RX filter setting by scenario.
6307 *
6308 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6309 */
6310 enum rtw_hal_status
rtw_hal_mac_set_rxfltr_by_mode(struct rtw_hal_com_t * hal_com,u8 band,enum rtw_rx_fltr_mode mode)6311 rtw_hal_mac_set_rxfltr_by_mode(struct rtw_hal_com_t *hal_com,
6312 u8 band, enum rtw_rx_fltr_mode mode)
6313 {
6314 struct hal_info_t *hal_info = hal_com->hal_priv;
6315 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6316 struct mac_ax_rx_fltr_ctrl_t ctrl = {0};
6317 struct mac_ax_rx_fltr_ctrl_t mask = {0};
6318 u32 err;
6319
6320
6321 switch (mode) {
6322 case RX_FLTR_MODE_RESTORE:
6323 break;
6324 case RX_FLTR_MODE_SNIFFER:
6325 ctrl.sniffer_mode = 1;
6326 mask.sniffer_mode = 1;
6327 break;
6328 case RX_FLTR_MODE_SCAN:
6329 ctrl.acpt_a1_match_pkt = 1;
6330 mask.acpt_a1_match_pkt = 1;
6331 ctrl.acpt_bc_pkt = 1;
6332 mask.acpt_bc_pkt = 1;
6333 ctrl.acpt_mc_pkt = 1;
6334 mask.acpt_mc_pkt = 1;
6335 ctrl.uc_pkt_chk_cam_match = 0;
6336 mask.uc_pkt_chk_cam_match = 1;
6337 ctrl.bc_pkt_chk_cam_match = 0;
6338 mask.bc_pkt_chk_cam_match = 1;
6339
6340 /* Do NOT check B_AX_A_BCN_CHK_RULE
6341 * when receiving beacon and probe_response
6342 */
6343 ctrl.bcn_chk_en = 0;
6344 mask.bcn_chk_en = 1;
6345 break;
6346 case RX_FLTR_MODE_STA_NORMAL:
6347 #if 1
6348 _hal_set_dft_rxfltr(&ctrl, &mask);
6349
6350 #else
6351 /* filter packets by address */
6352 ctrl.sniffer_mode = 0;
6353 mask.sniffer_mode = 1;
6354 /* check unicast */
6355 ctrl.acpt_a1_match_pkt = 1;
6356 mask.acpt_a1_match_pkt = 1;
6357 ctrl.uc_pkt_chk_cam_match = 1;
6358 mask.uc_pkt_chk_cam_match = 1;
6359 /* check broadcast */
6360 ctrl.acpt_bc_pkt = 1;
6361 mask.acpt_bc_pkt = 1;
6362 ctrl.bc_pkt_chk_cam_match = 1;
6363 mask.bc_pkt_chk_cam_match = 1;
6364
6365 if ((hal_com->chip_id == CHIP_WIFI6_8852A)
6366 && (hal_com->cv == CAV)) {
6367 /* don't check address cam for multicast, accept all */
6368 ctrl.acpt_mc_pkt = 0;
6369 mask.acpt_mc_pkt = 1;
6370 } else {
6371 /* check multicast */
6372 ctrl.acpt_mc_pkt = 1;
6373 mask.acpt_mc_pkt = 1;
6374 /* black list filter */
6375 ctrl.mc_pkt_white_lst_mode = 0;
6376 mask.mc_pkt_white_lst_mode = 1;
6377 }
6378 /* check beacon */
6379 ctrl.bcn_chk_en = 1;
6380 mask.bcn_chk_en = 1;
6381 ctrl.bcn_chk_rule = 2; /* 2: A2&A3 match */
6382 mask.bcn_chk_rule = 0x3;
6383 /* misc */
6384 ctrl.acpt_pwr_mngt_pkt = 1;
6385 mask.acpt_pwr_mngt_pkt = 1;
6386 ctrl.acpt_ftm_req_pkt = 1;
6387 mask.acpt_ftm_req_pkt = 1;
6388 #endif
6389 break;
6390 case RX_FLTR_MODE_STA_LINKING:
6391 #if 1
6392 _hal_set_dft_rxfltr(&ctrl, &mask);
6393 /* check broadcast */
6394 ctrl.acpt_bc_pkt = 1;
6395 mask.acpt_bc_pkt = 1;
6396 ctrl.bc_pkt_chk_cam_match = 0;
6397 mask.bc_pkt_chk_cam_match = 1;
6398
6399 /* check beacon */
6400 ctrl.bcn_chk_en = 0;
6401 mask.bcn_chk_en = 1;
6402
6403 #else
6404 /* filter packets by address */
6405 ctrl.sniffer_mode = 0;
6406 mask.sniffer_mode = 1;
6407 /* check unicast */
6408 ctrl.acpt_a1_match_pkt = 1;
6409 mask.acpt_a1_match_pkt = 1;
6410 ctrl.uc_pkt_chk_cam_match = 1;
6411 mask.uc_pkt_chk_cam_match = 1;
6412 /* check broadcast */
6413 ctrl.acpt_bc_pkt = 1;
6414 mask.acpt_bc_pkt = 1;
6415 ctrl.bc_pkt_chk_cam_match = 0;
6416 mask.bc_pkt_chk_cam_match = 1;
6417
6418 if ((hal_com->chip_id == CHIP_WIFI6_8852A)
6419 && (hal_com->cv == CAV)) {
6420 /* don't check address cam for multicast, accept all */
6421 ctrl.acpt_mc_pkt = 0;
6422 mask.acpt_mc_pkt = 1;
6423 } else {
6424 /* check multicast */
6425 ctrl.acpt_mc_pkt = 1;
6426 mask.acpt_mc_pkt = 1;
6427 /* black list filter */
6428 ctrl.mc_pkt_white_lst_mode = 0;
6429 mask.mc_pkt_white_lst_mode = 1;
6430 }
6431 /* check beacon */
6432 ctrl.bcn_chk_en = 0;
6433 mask.bcn_chk_en = 1;
6434 ctrl.bcn_chk_rule = 2; /* 2: A2&A3 match */
6435 mask.bcn_chk_rule = 0x3;
6436 /* misc */
6437 ctrl.acpt_pwr_mngt_pkt = 1;
6438 mask.acpt_pwr_mngt_pkt = 1;
6439 ctrl.acpt_ftm_req_pkt = 1;
6440 mask.acpt_ftm_req_pkt = 1;
6441 #endif
6442 break;
6443
6444 case RX_FLTR_MODE_AP_NORMAL:
6445 #if 1
6446 _hal_set_dft_rxfltr(&ctrl, &mask);
6447
6448 /* check unicast */
6449 ctrl.acpt_a1_match_pkt = 1;
6450 mask.acpt_a1_match_pkt = 1;
6451 ctrl.uc_pkt_chk_cam_match = 0;
6452 mask.uc_pkt_chk_cam_match = 1;
6453
6454 /* check broadcast (for probe req) */
6455 ctrl.acpt_bc_pkt = 1;
6456 mask.acpt_bc_pkt = 1;
6457 ctrl.bc_pkt_chk_cam_match = 0;
6458 mask.bc_pkt_chk_cam_match = 1;
6459
6460 #else
6461 /*
6462 * SNIFFER: OFF
6463 * UC address CAM A1: ON
6464 * UC addr CAM match: OFF
6465 * BC accept: ON
6466 * BC address CAM: OFF
6467 * Beacon check: OFF
6468 */
6469 /* filter packets by address */
6470 ctrl.sniffer_mode = 0;
6471 mask.sniffer_mode = 1;
6472 /* Unicast
6473 * Do not enable address CAM matching filtering but all A1
6474 * matched ones. AP should accept all UC requests from
6475 * unknown STAs.
6476 */
6477 ctrl.acpt_a1_match_pkt = 1;
6478 mask.acpt_a1_match_pkt = 1;
6479 ctrl.uc_pkt_chk_cam_match = 0;
6480 mask.uc_pkt_chk_cam_match = 1;
6481
6482 /* check broadcast (Probe req) */
6483 ctrl.acpt_bc_pkt = 1;
6484 mask.acpt_bc_pkt = 1;
6485 ctrl.bc_pkt_chk_cam_match = 0;
6486 mask.bc_pkt_chk_cam_match = 1;
6487
6488 if ((hal_com->chip_id == CHIP_WIFI6_8852A)
6489 && (hal_com->cv == CAV)) {
6490 /* don't check address cam for multicast, accept all */
6491 ctrl.acpt_mc_pkt = 1;
6492 mask.acpt_mc_pkt = 1;
6493 } else {
6494 /* check multicast */
6495 ctrl.acpt_mc_pkt = 1;
6496 mask.acpt_mc_pkt = 1;
6497 /* black list filter */
6498 ctrl.mc_pkt_white_lst_mode = 0;
6499 mask.mc_pkt_white_lst_mode = 1;
6500 }
6501
6502 /* check beacon */
6503 ctrl.bcn_chk_en = 1;
6504 mask.bcn_chk_en = 1;
6505 ctrl.bcn_chk_rule = 2; /* 2: A2&A3 match */
6506 mask.bcn_chk_rule = 0x3;
6507
6508 /* bcn_chk_rule
6509 0: A3 hit
6510 1: A2 hit
6511 2: A2 & A3 hit
6512 3: A2 | A3 hit
6513 */
6514 /* accept power management frame */
6515 ctrl.acpt_pwr_mngt_pkt = 1;
6516 mask.acpt_pwr_mngt_pkt = 1;
6517 ctrl.acpt_ftm_req_pkt = 1;
6518 mask.acpt_ftm_req_pkt = 1;
6519 #endif
6520 break;
6521
6522 }
6523
6524 err = mac->ops->set_rx_fltr_opt(mac, &ctrl, &mask, band);
6525 if (err)
6526 return RTW_HAL_STATUS_FAILURE;
6527
6528 return RTW_HAL_STATUS_SUCCESS;
6529 }
6530
6531 /**
6532 * rtw_hal_mac_set_rxfltr_acpt_crc_err - Accept CRC error packets or not
6533 * @hal_com: pointer of struct rtw_hal_com_t
6534 * @band: 0x0: band0, 0x1: band1
6535 * @enable: 0: deny, 1: accept
6536 *
6537 * Control accepting CRC error packets or not.
6538 *
6539 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6540 */
rtw_hal_mac_set_rxfltr_acpt_crc_err(struct rtw_hal_com_t * hal_com,u8 band,u8 enable)6541 enum rtw_hal_status rtw_hal_mac_set_rxfltr_acpt_crc_err(
6542 struct rtw_hal_com_t *hal_com, u8 band, u8 enable)
6543 {
6544 struct hal_info_t *hal_info = hal_com->hal_priv;
6545 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6546 struct mac_ax_rx_fltr_ctrl_t ctrl = {0};
6547 struct mac_ax_rx_fltr_ctrl_t mask = {0};
6548 u32 err;
6549
6550
6551 if (enable)
6552 ctrl.acpt_crc32_err_pkt = 1;
6553 else
6554 ctrl.acpt_crc32_err_pkt = 0;
6555 mask.acpt_crc32_err_pkt = 1;
6556
6557 err = mac->ops->set_rx_fltr_opt(mac, &ctrl, &mask, band);
6558 if (err)
6559 return RTW_HAL_STATUS_FAILURE;
6560
6561 return RTW_HAL_STATUS_SUCCESS;
6562 }
6563
6564 /**
6565 * rtw_hal_mac_set_rxfltr_mpdu_size - Set max MPDU size
6566 * @hal_com: pointer of struct rtw_hal_com_t
6567 * @band: 0x0: band0, 0x1: band1
6568 * @size: MPDU max size, unit: byte. 0 for no limit.
6569 *
6570 * MPDU size exceed Max size would be dropped.
6571 *
6572 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6573 */
rtw_hal_mac_set_rxfltr_mpdu_size(struct rtw_hal_com_t * hal_com,u8 band,u16 size)6574 enum rtw_hal_status rtw_hal_mac_set_rxfltr_mpdu_size(
6575 struct rtw_hal_com_t *hal_com, u8 band, u16 size)
6576 {
6577 struct hal_info_t *hal_info = hal_com->hal_priv;
6578 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6579 struct mac_ax_rx_fltr_ctrl_t ctrl = {0};
6580 struct mac_ax_rx_fltr_ctrl_t mask = {0};
6581 u32 err;
6582
6583
6584 /* unit of pkt_len_fltr is 512 bytes */
6585 ctrl.pkt_len_fltr = size >> 9;
6586 ctrl.pkt_len_fltr += (size & 0x7F) ? 1 : 0;
6587 mask.pkt_len_fltr = 0x3F;
6588
6589 err = mac->ops->set_rx_fltr_opt(mac, &ctrl, &mask, band);
6590 if (err)
6591 return RTW_HAL_STATUS_FAILURE;
6592
6593 return RTW_HAL_STATUS_SUCCESS;
6594 }
6595
6596 /**
6597 * rtw_hal_mac_set_rxfltr_by_type - Filter RX frame by frame type
6598 * @hal_com: pointer of struct rtw_hal_com_t
6599 * @band: 0x0: band0, 0x1: band1
6600 * @type: 802.11 frame type, b'00: mgmt, b'01: ctrl, b'10: data
6601 * @target: 0: drop, 1: accept(driver), 2: firmware
6602 *
6603 * Set RX filter setting by 802.11 frame type and frame would be dropped or
6604 * forward to specific target.
6605 *
6606 * Return RTW_HAL_STATUS_SUCCESS when setting is ok, otherwise fail.
6607 */
rtw_hal_mac_set_rxfltr_by_type(struct rtw_hal_com_t * hal_com,u8 band,u8 type,u8 target)6608 enum rtw_hal_status rtw_hal_mac_set_rxfltr_by_type(
6609 struct rtw_hal_com_t *hal_com, u8 band, u8 type, u8 target)
6610 {
6611 struct hal_info_t *hal_info = hal_com->hal_priv;
6612 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6613 enum mac_ax_pkt_t ftype;
6614 enum mac_ax_fwd_target fwd;
6615 u32 err;
6616
6617
6618 switch (type) {
6619 case RTW_PHL_PKT_TYPE_MGNT:
6620 ftype = MAC_AX_PKT_MGNT;
6621 break;
6622 case RTW_PHL_PKT_TYPE_CTRL:
6623 ftype = MAC_AX_PKT_CTRL;
6624 break;
6625 case RTW_PHL_PKT_TYPE_DATA:
6626 ftype = MAC_AX_PKT_DATA;
6627 break;
6628 default:
6629 return RTW_HAL_STATUS_FAILURE;
6630 }
6631
6632 if (target > MAC_AX_FWD_TO_WLAN_CPU)
6633 return RTW_HAL_STATUS_FAILURE;
6634 fwd = (enum mac_ax_fwd_target)target;
6635
6636 err = mac->ops->set_rx_fltr_typ_opt(mac, ftype, fwd, band);
6637 if (err)
6638 return RTW_HAL_STATUS_FAILURE;
6639
6640 return RTW_HAL_STATUS_SUCCESS;
6641 }
6642
6643 /**
6644 * rtw_hal_mac_set_rxfltr_by_subtype - Filter RX frame by frame type & subtype
6645 * @hal_com: pointer of struct rtw_hal_com_t
6646 * @band: 0x0: band0, 0x1: band1
6647 * @type: 802.11 frame type, b'00: mgmt, b'01: ctrl, b'10: data
6648 * @subtype: 802.11 frame subtype, value range is 0x00~0xFF.
6649 * @target: 0: drop, 1: accept(driver), 2: firmware
6650 *
6651 * Set RX filter setting by 802.11 frame type and subtype, then frame would be
6652 * dropped or forward to specific target.
6653 *
6654 * Return RTW_HAL_STATUS_SUCCESS when setting is ok, otherwise fail.
6655 */
rtw_hal_mac_set_rxfltr_by_subtype(struct rtw_hal_com_t * hal_com,u8 band,u8 type,u8 subtype,u8 target)6656 enum rtw_hal_status rtw_hal_mac_set_rxfltr_by_subtype(
6657 struct rtw_hal_com_t *hal_com, u8 band,
6658 u8 type, u8 subtype, u8 target)
6659 {
6660 struct hal_info_t *hal_info = hal_com->hal_priv;
6661 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6662 enum mac_ax_pkt_t ftype;
6663 enum mac_ax_fwd_target fwd;
6664 u32 err;
6665
6666
6667 switch (type) {
6668 case 0:
6669 ftype = MAC_AX_PKT_MGNT;
6670 break;
6671 case 1:
6672 ftype = MAC_AX_PKT_CTRL;
6673 break;
6674 case 2:
6675 ftype = MAC_AX_PKT_DATA;
6676 break;
6677 default:
6678 return RTW_HAL_STATUS_FAILURE;
6679 }
6680
6681 if (subtype > 0xFF)
6682 return RTW_HAL_STATUS_FAILURE;
6683
6684 if (target > MAC_AX_FWD_TO_WLAN_CPU)
6685 return RTW_HAL_STATUS_FAILURE;
6686 fwd = (enum mac_ax_fwd_target)target;
6687
6688 err = mac->ops->set_rx_fltr_typstyp_opt(mac, ftype, subtype, fwd, band);
6689 if (err)
6690 return RTW_HAL_STATUS_FAILURE;
6691 return RTW_HAL_STATUS_SUCCESS;
6692 }
6693
6694 enum rtw_hal_status
rtw_hal_mac_enable_bb_rf(struct hal_info_t * hal_info,u8 enable)6695 rtw_hal_mac_enable_bb_rf(struct hal_info_t *hal_info, u8 enable)
6696 {
6697 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
6698
6699 mac->ops->set_hw_value(mac, MAC_AX_HW_EN_BB_RF, &enable);
6700 return RTW_HAL_STATUS_SUCCESS;
6701 }
6702
6703 void
rtw_hal_mac_get_buffer_data(struct rtw_hal_com_t * hal_com,u32 strt_addr,u8 * buf,u32 len,u32 dbg_path)6704 rtw_hal_mac_get_buffer_data(struct rtw_hal_com_t *hal_com, u32 strt_addr,
6705 u8 *buf, u32 len, u32 dbg_path)
6706 {
6707 struct hal_info_t *hal_info = hal_com->hal_priv;
6708 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6709
6710 mac_mem_dump(mac, MAC_AX_MEM_SHARED_BUF, strt_addr, buf, len, dbg_path);
6711 }
6712
6713 void
rtl_hal_dump_sec_cam_tbl(struct rtw_hal_com_t * hal_com)6714 rtl_hal_dump_sec_cam_tbl(struct rtw_hal_com_t *hal_com)
6715 {
6716 u32 i = 0;
6717 u32 sec_cam_tbl_sz = 128;
6718 struct hal_info_t *hal = hal_com->hal_priv;
6719 struct mac_ax_adapter *mac = hal_to_mac(hal);
6720 struct sec_cam_table_t *sec_cam_table = mac->hw_info->sec_cam_table;
6721 struct sec_cam_entry_t *entry = NULL;
6722
6723 PHL_PRINT("===== HW Info Security CAM Table =====\n");
6724 PHL_PRINT("entry valid mac_id key_id key_type\n");
6725 for (i = 0; i < sec_cam_tbl_sz; i++) {
6726 entry = sec_cam_table->sec_cam_entry[i];
6727 if (entry == NULL)
6728 continue;
6729
6730 PHL_PRINT(" %3d %3d %3d %3d %3d\n",
6731 i, entry->valid, entry->mac_id, entry->key_id, entry->key_type);
6732 }
6733 }
6734
halmac_cmd_parser(struct hal_info_t * hal_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)6735 void halmac_cmd_parser(struct hal_info_t *hal_info, char input[][MAX_ARGV],
6736 u32 input_num, char *output, u32 out_len)
6737 {
6738 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6739
6740 mac->ops->halmac_cmd_parser(mac, input, input_num, output, out_len);
6741 }
6742
6743
halmac_cmd(struct hal_info_t * hal_info,char * input,char * output,u32 out_len)6744 s32 halmac_cmd(struct hal_info_t *hal_info, char *input, char *output, u32 out_len)
6745 {
6746 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6747
6748 return mac->ops->halmac_cmd(mac, input, output, out_len);
6749 }
6750
rtw_hal_mac_proc_cmd(struct hal_info_t * hal_info,struct rtw_proc_cmd * incmd,char * output,u32 out_len)6751 bool rtw_hal_mac_proc_cmd(struct hal_info_t *hal_info, struct rtw_proc_cmd *incmd,
6752 char *output, u32 out_len)
6753 {
6754 if(incmd->in_type == RTW_ARG_TYPE_BUF)
6755 halmac_cmd(hal_info, incmd->in.buf, output, out_len);
6756 else if(incmd->in_type == RTW_ARG_TYPE_ARRAY){
6757 halmac_cmd_parser(hal_info, incmd->in.vector,
6758 incmd->in_cnt_len, output, out_len);
6759 }
6760
6761 return true;
6762 }
6763
_ac_drv2mac(u8 ac,u8 wmm)6764 static enum mac_ax_cmac_path_sel _ac_drv2mac(u8 ac, u8 wmm)
6765 {
6766 enum mac_ax_cmac_path_sel sel = MAC_AX_CMAC_PATH_SEL_INVALID;
6767
6768
6769 switch (ac) {
6770 case 0:
6771 /* BE */
6772 sel = MAC_AX_CMAC_PATH_SEL_BE0;
6773 break;
6774 case 1:
6775 /* BK */
6776 sel = MAC_AX_CMAC_PATH_SEL_BK0;
6777 break;
6778 case 2:
6779 /* VI */
6780 sel = MAC_AX_CMAC_PATH_SEL_VI0;
6781 break;
6782 case 3:
6783 /* VO */
6784 sel = MAC_AX_CMAC_PATH_SEL_VO0;
6785 break;
6786 }
6787
6788 if (sel != MAC_AX_CMAC_PATH_SEL_INVALID && wmm)
6789 /* wmm == 1 */
6790 sel += 4;
6791
6792 return sel;
6793 }
6794
6795 /**
6796 * rtw_hal_mac_set_edca() - setup WMM EDCA parameter
6797 * @hal_com: struct rtw_hal_com_t *
6798 * @band: 0x0: band0, 0x1: band1
6799 * @wmm: hardware wmm index
6800 * @ac: Access Category, 0:BE, 1:BK, 2:VI, 3:VO
6801 * @param: AIFS:BIT[7:0], CWMIN:BIT[11:8], CWMAX:BIT[15:12],
6802 * TXOP:BIT[31:16]
6803 *
6804 * Setup WMM EDCA parameter set for specific AC.
6805 *
6806 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6807 */
6808 enum rtw_hal_status
rtw_hal_mac_set_edca(struct rtw_hal_com_t * hal_com,u8 band,u8 wmm,u8 ac,u32 param)6809 rtw_hal_mac_set_edca(struct rtw_hal_com_t *hal_com, u8 band, u8 wmm, u8 ac,
6810 u32 param)
6811 {
6812 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
6813 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6814 struct mac_ax_edca_param edca = {0};
6815 u32 err = 0;
6816
6817
6818 edca.band = band;
6819 edca.path = _ac_drv2mac(ac, wmm);
6820 edca.txop_32us = param >> 16;
6821 edca.ecw_max = (param >> 12) & 0xF;
6822 edca.ecw_min = (param >> 8) & 0xF;
6823 edca.aifs_us = param & 0xFF;
6824
6825 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_EDCA_PARAM, &edca);
6826 if (err)
6827 return RTW_HAL_STATUS_FAILURE;
6828
6829 return RTW_HAL_STATUS_SUCCESS;
6830 }
6831
6832 #ifdef CONFIG_PHL_TWT
6833 enum rtw_hal_status
rtw_hal_mac_twt_info_update(void * hal,struct rtw_phl_twt_info twt_info,struct rtw_wifi_role_t * role,u8 action)6834 rtw_hal_mac_twt_info_update(void *hal, struct rtw_phl_twt_info twt_info, struct rtw_wifi_role_t *role, u8 action)
6835 {
6836 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
6837 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6838 struct mac_ax_twt_para mac_twt_para = {0};
6839 u32 mac_status = MACSUCCESS;
6840
6841 switch (twt_info.nego_type)
6842 {
6843 case RTW_PHL_INDIV_TWT:
6844 mac_twt_para.nego_tp = MAC_AX_TWT_NEGO_TP_IND;
6845 mac_twt_para.flow_id = 0;
6846 break;
6847 case RTW_PHL_WAKE_TBTT_INR:
6848 mac_twt_para.nego_tp = MAC_AX_TWT_NEGO_TP_WAKE;
6849 mac_twt_para.flow_id = 0;
6850 break;
6851 case RTW_PHL_BCAST_TWT:
6852 mac_twt_para.nego_tp = MAC_AX_TWT_NEGO_TP_BRC;
6853 mac_twt_para.flow_id = twt_info.bcast_twt_id;
6854 break;
6855 default:
6856 PHL_ERR("%s : Error TWT nego type %d\n", __func__, twt_info.nego_type);
6857 return RTW_HAL_STATUS_FAILURE;
6858 }
6859 switch (action) {
6860 case TWT_CFG_ADD:
6861 mac_twt_para.act = MAC_AX_TWT_ACT_TP_ADD;
6862 break;
6863 case TWT_CFG_DELETE:
6864 mac_twt_para.act = MAC_AX_TWT_ACT_TP_DEL;
6865 break;
6866 case TWT_CFG_MODIFY:
6867 mac_twt_para.act = MAC_AX_TWT_ACT_TP_MOD;
6868 break;
6869 default:
6870 PHL_ERR("%s : Error TWT action %d\n", __func__, action);
6871 return RTW_HAL_STATUS_FAILURE;
6872 }
6873 mac_twt_para.trig = twt_info.trigger;
6874 mac_twt_para.flow_tp = twt_info.flow_type;
6875 mac_twt_para.proct = twt_info.twt_protection;
6876 mac_twt_para.id = twt_info.twt_id;
6877 mac_twt_para.wake_exp = twt_info.twt_wake_int_exp;
6878 mac_twt_para.band = role->hw_band;
6879 mac_twt_para.port = role->hw_port;
6880 mac_twt_para.rsp_pm = twt_info.responder_pm_mode;
6881 mac_twt_para.wake_unit = twt_info.wake_dur_unit;
6882 mac_twt_para.impt = twt_info.implicit_lastbcast;
6883 mac_twt_para.wake_man = twt_info.twt_wake_int_mantissa;
6884 mac_twt_para.dur = twt_info.nom_min_twt_wake_dur;
6885 mac_twt_para.trgt_l = twt_info.target_wake_time_l;
6886 mac_twt_para.trgt_h = twt_info.target_wake_time_h;
6887 /* HalMac API to setup/delete TWT config*/
6888 mac_status = mac->ops->twt_info_upd_h2c(mac, &mac_twt_para);
6889 if (MACSUCCESS != mac_status){
6890 PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_hal_mac_twt_info_update(): mac_twt_info_upd_h2c fail(%d)\n",
6891 mac_status);
6892 return RTW_HAL_STATUS_FAILURE;
6893 }
6894 return RTW_HAL_STATUS_SUCCESS;
6895 }
6896
6897 enum rtw_hal_status
rtw_hal_mac_twt_sta_update(void * hal,u8 macid,u8 twt_id,u8 action)6898 rtw_hal_mac_twt_sta_update(void *hal, u8 macid, u8 twt_id, u8 action)
6899 {
6900 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
6901 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6902 struct mac_ax_twtact_para mac_twtact_para = {0};
6903 u32 mac_status = MACSUCCESS;
6904
6905 switch (action) {
6906 case TWT_STA_ADD_MACID:
6907 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_ADD;
6908 break;
6909 case TWT_STA_DEL_MACID:
6910 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_DEL;
6911 break;
6912 case TWT_STA_TETMINATW_SP:
6913 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_TRMNT;
6914 break;
6915 case TWT_STA_SUSPEND_TWT:
6916 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_SUS;
6917 break;
6918 case TWT_STA_RESUME_TWT:
6919 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_RSUM;
6920 break;
6921 default:
6922 PHL_ERR("%s : Error TWT action %d\n", __func__, action);
6923 return RTW_HAL_STATUS_FAILURE;
6924 }
6925 mac_twtact_para.macid = macid;
6926 mac_twtact_para.id = twt_id;
6927 /* Call HalMac API to setup/delete TWT STA config*/
6928 mac_status = mac->ops->twt_act_h2c(mac, &mac_twtact_para);
6929 if (MACSUCCESS != mac_status) {
6930 PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_hal_mac_twt_sta_update(): mac_twt_act_h2c fail(%d)\n",
6931 mac_status);
6932 return RTW_HAL_STATUS_FAILURE;
6933 }
6934 return RTW_HAL_STATUS_SUCCESS;
6935 }
6936
6937 enum rtw_hal_status
rtw_hal_mac_twt_sta_announce(void * hal,u8 macid)6938 rtw_hal_mac_twt_sta_announce(void *hal, u8 macid)
6939 {
6940 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
6941 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6942 struct mac_ax_twtanno_para mac_twtanno_para = {0};
6943 u32 mac_status = MACSUCCESS;
6944
6945 mac_twtanno_para.macid = macid;
6946 mac_status = mac->ops->twt_anno_h2c(mac, &mac_twtanno_para);
6947 if (MACSUCCESS != mac_status) {
6948 PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_hal_mac_twt_sta_announce(): mac_twt_anno_h2c fail(%d)\n",
6949 mac_status);
6950 return RTW_HAL_STATUS_FAILURE;
6951 }
6952 return RTW_HAL_STATUS_SUCCESS;
6953 }
6954 #endif /* CONFIG_PHL_TWT */
6955
6956 /**
6957 * rtw_hal_mac_get_ampdu_cfg() - get ampdu config
6958 * @hal_com: struct rtw_hal_com_t *
6959 * @band: 0x0: band0, 0x1: band1
6960 * @cfg: struct hal_ax_ampdu_cfg *
6961 * Get ampdu config.
6962 * Return RTW_HAL_STATUS_SUCCESS when query is done.
6963 */
6964 enum rtw_hal_status
rtw_hal_mac_get_ampdu_cfg(struct rtw_hal_com_t * hal_com,u8 band,struct mac_ax_ampdu_cfg * cfg)6965 rtw_hal_mac_get_ampdu_cfg(struct rtw_hal_com_t *hal_com,
6966 u8 band,
6967 struct mac_ax_ampdu_cfg *cfg)
6968 {
6969 /* To Do: need to refine after Mac api updating*/
6970 #if 0
6971 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
6972 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6973
6974 u32 err = 0;
6975 cfg->band = band;
6976 err = mac->ops->get_hw_value(mac, MAC_AX_HW_GET_AMPDU_CFG, cfg);
6977 if (err)
6978 return RTW_HAL_STATUS_FAILURE;
6979 #endif
6980 return RTW_HAL_STATUS_SUCCESS;
6981 }
6982
6983 /*
6984 * rtw_hal_mac_set_rty_lmt() - setup retry limit parameter
6985 * @hal_com: struct rtw_hal_com_t *
6986 * @macid:
6987 *
6988 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6989 */
6990 enum rtw_hal_status
rtw_hal_mac_set_rty_lmt(struct rtw_hal_com_t * hal_com,u8 macid,u8 rts_lmt_sel,u8 rts_lmt_val,u8 data_lmt_sel,u8 data_lmt_val)6991 rtw_hal_mac_set_rty_lmt(struct rtw_hal_com_t *hal_com, u8 macid,
6992 u8 rts_lmt_sel, u8 rts_lmt_val, u8 data_lmt_sel, u8 data_lmt_val)
6993 {
6994 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
6995 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6996 struct mac_ax_cctl_rty_lmt_cfg cfg = {0};
6997 u32 err = 0;
6998
6999
7000 cfg.macid = macid;
7001 cfg.data_lmt_sel = data_lmt_sel;
7002 cfg.data_lmt_val = data_lmt_val;
7003 cfg.rts_lmt_sel = rts_lmt_sel;
7004 cfg.rts_lmt_val = rts_lmt_val;
7005
7006 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_CCTL_RTY_LMT, &cfg);
7007 if (err)
7008 return RTW_HAL_STATUS_FAILURE;
7009
7010 return RTW_HAL_STATUS_SUCCESS;
7011 }
7012
7013 /**
7014 * rtw_hal_mac_is_tx_mgnt_empty() - Get tx mgnt queue status
7015 * @hal_info: struct rtw_hal_info_t *
7016 * @band: 0x0: band0, 0x1: band1
7017 * @st: queue status, 1 for empty and 0 for not empty.
7018 *
7019 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
7020 */
7021 enum rtw_hal_status
rtw_hal_mac_is_tx_mgnt_empty(struct hal_info_t * hal_info,u8 band,u8 * st)7022 rtw_hal_mac_is_tx_mgnt_empty(struct hal_info_t *hal_info, u8 band, u8 *st)
7023 {
7024 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7025 struct mac_ax_tx_queue_empty q_st = {{0}};
7026 u32 err;
7027
7028
7029 err = mac->ops->is_txq_empty(mac, &q_st);
7030 if (err != MACSUCCESS)
7031 return RTW_HAL_STATUS_FAILURE;
7032
7033 if ((band == 0) && (q_st.band0_mgnt_empty == DLE_QUEUE_EMPTY))
7034 *st = 1;
7035 else if ((band == 1) && (q_st.band1_mgnt_empty == DLE_QUEUE_EMPTY))
7036 *st = 1;
7037 else
7038 *st = 0;
7039
7040 return RTW_HAL_STATUS_SUCCESS;
7041 }
7042
7043
7044 /* FW Sounding Command */
7045 /* 1. NDPA Content */
_hal_max_ax_snd_cmd_ndpa(struct mac_ax_ndpa_para * mac_ndpa,struct hal_ndpa_para * hal_ndpa,bool he,u8 sta_nr)7046 void _hal_max_ax_snd_cmd_ndpa(struct mac_ax_ndpa_para *mac_ndpa,
7047 struct hal_ndpa_para *hal_ndpa,
7048 bool he, u8 sta_nr)
7049 {
7050 u8 i = 0;
7051 struct hal_he_ndpa_sta_info *hal_he_sta = NULL;
7052 struct hal_vht_ndpa_sta_info *hal_vht_sta = NULL;
7053
7054 mac_ndpa->common.frame_ctl = hal_ndpa->common.frame_ctl;
7055 mac_ndpa->common.duration = hal_ndpa->common.duration;
7056 for (i = 0; i < MAC_ALEN; i++) {
7057 mac_ndpa->common.addr1[i] = hal_ndpa->common.addr1[i];
7058 mac_ndpa->common.addr2[i] = hal_ndpa->common.addr2[i];
7059 }
7060 mac_ndpa->snd_dialog.dialog = hal_ndpa->snd_dialog.token;
7061 mac_ndpa->snd_dialog.he = hal_ndpa->snd_dialog.he;
7062 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "halmac he 0x%x sta_nr %d \n", he, sta_nr);
7063 if (he) {
7064 for (i = 0; (i < sta_nr)&&(i < HAL_MAX_HE_SND_STA_NUM); i++) {
7065 hal_he_sta = (struct hal_he_ndpa_sta_info *)
7066 &hal_ndpa->ndpa_sta_info[i];
7067 mac_ndpa->he_para.sta_info[i].aid = hal_he_sta->aid;
7068 mac_ndpa->he_para.sta_info[i].bw = hal_he_sta->bw;
7069 mac_ndpa->he_para.sta_info[i].fb_ng = hal_he_sta->fb_ng;
7070 mac_ndpa->he_para.sta_info[i].disambiguation = 1;
7071 mac_ndpa->he_para.sta_info[i].cb = hal_he_sta->cb;//cb nc
7072 mac_ndpa->he_para.sta_info[i].nc = hal_he_sta->nc;//cb nc
7073 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "halmac cmd buf HE (%d) : aid 0x%x bw 0x%x fbng 0x%x cb 0x%x nc 0x%x\n",
7074 i, mac_ndpa->he_para.sta_info[i].aid,
7075 mac_ndpa->he_para.sta_info[i].bw,
7076 mac_ndpa->he_para.sta_info[i].fb_ng,
7077 mac_ndpa->he_para.sta_info[i].cb,
7078 mac_ndpa->he_para.sta_info[i].nc);
7079 }
7080 } else {
7081 for (i = 0; (i < sta_nr)&&(i < HAL_MAX_VHT_SND_STA_NUM); i++) {
7082 hal_vht_sta = (struct hal_vht_ndpa_sta_info *)
7083 &hal_ndpa->ndpa_sta_info[i];
7084 mac_ndpa->vht_para.sta_info[i].aid =
7085 (u16)hal_vht_sta->aid12;
7086 mac_ndpa->vht_para.sta_info[i].fb_type =
7087 (u16)hal_vht_sta->feedback_type;
7088 mac_ndpa->vht_para.sta_info[i].nc =
7089 (u16)hal_vht_sta->nc;
7090 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "halmac cmd buf VHT(%d) : aid 0x%x fb 0x%x nc 0x%x\n",
7091 i,
7092 mac_ndpa->vht_para.sta_info[i].aid,
7093 mac_ndpa->vht_para.sta_info[i].fb_type,
7094 mac_ndpa->vht_para.sta_info[i].nc);
7095 }
7096 }
7097 }
7098 /* 2-1. BFRP Content - VHT */
_hal_max_ax_snd_cmd_bfrp_vht(struct mac_ax_bfrp_para * mac_bfrp,struct hal_bfrp_para * hal_bfrp,u8 bfrp_num)7099 void _hal_max_ax_snd_cmd_bfrp_vht(struct mac_ax_bfrp_para *mac_bfrp,
7100 struct hal_bfrp_para *hal_bfrp, u8 bfrp_num)
7101 {
7102 struct mac_ax_vht_bfrp_para *mac_vht_bfrp = NULL;
7103 struct hal_bfrp_vht *hal_vht_bfrp = NULL;
7104 u8 i = 0, j = 0;
7105 for (i = 0; (i <= bfrp_num)&&(i < HAL_MAX_VHT_BFRP_NUM); i++){
7106 mac_bfrp->hdr[i].frame_ctl = hal_bfrp->hdr[i].frame_ctl;
7107 mac_bfrp->hdr[i].duration = hal_bfrp->hdr[i].duration;
7108 for (j = 0; j < MAC_ALEN; j++) {
7109 mac_bfrp->hdr[i].addr1[j] = hal_bfrp->hdr[i].addr1[j];
7110 mac_bfrp->hdr[i].addr2[j] = hal_bfrp->hdr[i].addr2[j];
7111 }
7112 mac_vht_bfrp = &mac_bfrp->vht_para[i];
7113 hal_vht_bfrp = &hal_bfrp->vht_para[i];
7114 mac_vht_bfrp->retransmission_bitmap = hal_vht_bfrp->rexmit_bmp;
7115 }
7116 }
7117 /* 2-2. BFRP Content - HE */
_hal_max_ax_snd_cmd_bfrp_he(struct mac_ax_bfrp_para * mac_bfrp,struct hal_bfrp_para * hal_bfrp,u8 num_1,u8 num_2)7118 void _hal_max_ax_snd_cmd_bfrp_he(struct mac_ax_bfrp_para *mac_bfrp,
7119 struct hal_bfrp_para *hal_bfrp,
7120 u8 num_1, u8 num_2)
7121 {
7122 u8 i = 0;
7123 struct mac_ax_he_bfrp_para *mac_he_bfrp = NULL;
7124 struct hal_bfrp_he *hal_he_bfrp = NULL;
7125
7126 /* BFRP-0 */
7127 if (num_1) {
7128 mac_bfrp->hdr[0].frame_ctl = hal_bfrp->hdr[0].frame_ctl;
7129 mac_bfrp->hdr[0].duration = hal_bfrp->hdr[0].duration;
7130 for (i = 0; i < MAC_ALEN; i++) {
7131 mac_bfrp->hdr[0].addr1[i] = hal_bfrp->hdr[0].addr1[i];
7132 mac_bfrp->hdr[0].addr2[i] = hal_bfrp->hdr[0].addr2[i];
7133 }
7134 mac_he_bfrp = &mac_bfrp->he_para[0];
7135 hal_he_bfrp = &hal_bfrp->he_para[0];
7136 mac_he_bfrp->common.tgr_info = hal_he_bfrp->common.tgr_info;
7137 mac_he_bfrp->common.ul_len = hal_he_bfrp->common.ul_len;
7138 mac_he_bfrp->common.more_tf = hal_he_bfrp->common.more_tf;
7139 mac_he_bfrp->common.cs_rqd = hal_he_bfrp->common.cs_rqd;
7140 mac_he_bfrp->common.ul_bw = hal_he_bfrp->common.ul_bw;
7141 mac_he_bfrp->common.gi_ltf = hal_he_bfrp->common.gi_ltf;
7142 mac_he_bfrp->common.mimo_ltfmode =
7143 hal_he_bfrp->common.mimo_ltfmode;
7144 mac_he_bfrp->common.num_heltf = hal_he_bfrp->common.num_heltf;
7145 mac_he_bfrp->common.ul_pktext = hal_he_bfrp->common.ul_pktext;
7146 mac_he_bfrp->common.ul_stbc = hal_he_bfrp->common.ul_stbc;
7147 mac_he_bfrp->common.ldpc_extra_sym =
7148 hal_he_bfrp->common.ldpc_extra_sym;
7149 mac_he_bfrp->common.dplr = hal_he_bfrp->common.dplr;
7150 mac_he_bfrp->common.ap_tx_pwr = hal_he_bfrp->common.ap_tx_pwr;
7151 mac_he_bfrp->common.ul_sr = hal_he_bfrp->common.ul_sr;
7152 mac_he_bfrp->common.ul_siga2_rsvd =
7153 hal_he_bfrp->common.ul_siga2_rsvd;
7154 for( i = 0; (i < num_1)&&(i < HAL_MAX_HE_BFRP_STA_NUM); i++) {
7155 mac_he_bfrp->user[i].aid12 =
7156 hal_he_bfrp->user[i].aid12;
7157 mac_he_bfrp->user[i].fbseg_rexmit_bmp =
7158 hal_he_bfrp->fbseg_rexmit_bmp[i];
7159 mac_he_bfrp->user[i].ru_pos =
7160 hal_he_bfrp->user[i].ru_pos;
7161 mac_he_bfrp->user[i].ss_alloc =
7162 hal_he_bfrp->user[i].ss_alloc;
7163 mac_he_bfrp->user[i].ul_dcm =
7164 hal_he_bfrp->user[i].ul_dcm;
7165 mac_he_bfrp->user[i].ul_fec_code =
7166 hal_he_bfrp->user[i].ul_fec_code;
7167 mac_he_bfrp->user[i].ul_mcs =
7168 hal_he_bfrp->user[i].ul_mcs;
7169 mac_he_bfrp->user[i].ul_tgt_rssi =
7170 hal_he_bfrp->user[i].ul_tgt_rssi;
7171 }
7172 }
7173 /* BFRP - 1 */
7174 if (num_2) {
7175 mac_bfrp->hdr[1].frame_ctl = hal_bfrp->hdr[1].frame_ctl;
7176 mac_bfrp->hdr[1].duration = hal_bfrp->hdr[1].duration;
7177 for (i = 0; i < MAC_ALEN; i++) {
7178 mac_bfrp->hdr[1].addr1[i] = hal_bfrp->hdr[1].addr1[i];
7179 mac_bfrp->hdr[1].addr2[i] = hal_bfrp->hdr[1].addr2[i];
7180 }
7181 mac_he_bfrp = &mac_bfrp->he_para[1];
7182 hal_he_bfrp = &hal_bfrp->he_para[1];
7183 mac_he_bfrp->common.tgr_info = hal_he_bfrp->common.tgr_info;
7184 mac_he_bfrp->common.ul_len = hal_he_bfrp->common.ul_len;
7185 mac_he_bfrp->common.more_tf = hal_he_bfrp->common.more_tf;
7186 mac_he_bfrp->common.cs_rqd = hal_he_bfrp->common.cs_rqd;
7187 mac_he_bfrp->common.ul_bw = hal_he_bfrp->common.ul_bw;
7188 mac_he_bfrp->common.gi_ltf = hal_he_bfrp->common.gi_ltf;
7189 mac_he_bfrp->common.mimo_ltfmode =
7190 hal_he_bfrp->common.mimo_ltfmode;
7191 mac_he_bfrp->common.num_heltf = hal_he_bfrp->common.num_heltf;
7192 mac_he_bfrp->common.ul_pktext = hal_he_bfrp->common.ul_pktext;
7193 mac_he_bfrp->common.ul_stbc = hal_he_bfrp->common.ul_stbc;
7194 mac_he_bfrp->common.ldpc_extra_sym =
7195 hal_he_bfrp->common.ldpc_extra_sym;
7196 mac_he_bfrp->common.dplr = hal_he_bfrp->common.dplr;
7197 mac_he_bfrp->common.ap_tx_pwr = hal_he_bfrp->common.ap_tx_pwr;
7198 mac_he_bfrp->common.ul_sr = hal_he_bfrp->common.ul_sr;
7199 mac_he_bfrp->common.ul_siga2_rsvd =
7200 hal_he_bfrp->common.ul_siga2_rsvd;
7201 for( i = 0; (i < num_1)&&(i < HAL_MAX_HE_BFRP_STA_NUM); i++) {
7202 mac_he_bfrp->user[i].aid12 =
7203 hal_he_bfrp->user[i].aid12;
7204 mac_he_bfrp->user[i].fbseg_rexmit_bmp =
7205 hal_he_bfrp->fbseg_rexmit_bmp[i];
7206 mac_he_bfrp->user[i].ru_pos =
7207 hal_he_bfrp->user[i].ru_pos;
7208 mac_he_bfrp->user[i].ss_alloc =
7209 hal_he_bfrp->user[i].ss_alloc;
7210 mac_he_bfrp->user[i].ul_dcm =
7211 hal_he_bfrp->user[i].ul_dcm;
7212 mac_he_bfrp->user[i].ul_fec_code =
7213 hal_he_bfrp->user[i].ul_fec_code;
7214 mac_he_bfrp->user[i].ul_mcs =
7215 hal_he_bfrp->user[i].ul_mcs;
7216 mac_he_bfrp->user[i].ul_tgt_rssi =
7217 hal_he_bfrp->user[i].ul_tgt_rssi;
7218 }
7219 }
7220 }
7221
7222 /* 2-3 he bfrp f2p cmd */
_hal_max_ax_snd_cmd_bfrp_he_f2p(struct mac_ax_snd_f2P * mac_bfrp_f2p,struct hal_bfrp_para * hal_bfrp,u8 num_1,u8 num_2)7223 void _hal_max_ax_snd_cmd_bfrp_he_f2p(struct mac_ax_snd_f2P *mac_bfrp_f2p,
7224 struct hal_bfrp_para *hal_bfrp,
7225 u8 num_1, u8 num_2)
7226 {
7227 struct hal_bfrp_he *hal_he_bfrp = NULL;
7228 if (num_1) {
7229 hal_he_bfrp = &hal_bfrp->he_para[0];
7230 mac_bfrp_f2p[0].csi_len_bfrp =
7231 hal_he_bfrp->f2p_info.csi_len_bfrp;
7232 mac_bfrp_f2p[0].tb_t_pe_bfrp =
7233 hal_he_bfrp->f2p_info.tb_t_pe_bfrp;
7234 mac_bfrp_f2p[0].tri_pad_bfrp =
7235 hal_he_bfrp->f2p_info.tri_pad_bfrp;
7236 mac_bfrp_f2p[0].ul_cqi_rpt_tri_bfrp =
7237 hal_he_bfrp->f2p_info.ul_cqi_rpt_tri_bfrp;
7238 mac_bfrp_f2p[0].rf_gain_idx_bfrp =
7239 hal_he_bfrp->f2p_info.rf_gain_idx_bfrp;
7240 mac_bfrp_f2p[0].fix_gain_en_bfrp =
7241 hal_he_bfrp->f2p_info.fix_gain_en_bfrp;
7242 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7243 "==> _hal_max_ax_snd_cmd_bfrp_he_f2p[0] \n");
7244 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7245 "mac_bfrp_f2p[0].csi_len_bfrp = 0x%x \n",
7246 mac_bfrp_f2p[0].csi_len_bfrp);
7247 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7248 "mac_bfrp_f2p[0].tb_t_pe_bfrp = 0x%x \n",
7249 mac_bfrp_f2p[0].tb_t_pe_bfrp);
7250 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7251 "mac_bfrp_f2p[0].tri_pad_bfrp = 0x%x \n",
7252 mac_bfrp_f2p[0].tri_pad_bfrp);
7253 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7254 "mac_bfrp_f2p[0].ul_cqi_rpt_tri_bfrp = 0x%x \n",
7255 mac_bfrp_f2p[0].ul_cqi_rpt_tri_bfrp);
7256 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7257 "mac_bfrp_f2p[0].rf_gain_idx_bfrp = 0x%x \n",
7258 mac_bfrp_f2p[0].rf_gain_idx_bfrp);
7259 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7260 "mac_bfrp_f2p[0].fix_gain_en_bfrp = 0x%x \n",
7261 mac_bfrp_f2p[0].fix_gain_en_bfrp);
7262 }
7263 if (num_2) {
7264 hal_he_bfrp = &hal_bfrp->he_para[1];
7265 mac_bfrp_f2p[1].csi_len_bfrp =
7266 hal_he_bfrp->f2p_info.csi_len_bfrp;
7267 mac_bfrp_f2p[1].tb_t_pe_bfrp =
7268 hal_he_bfrp->f2p_info.tb_t_pe_bfrp;
7269 mac_bfrp_f2p[1].tri_pad_bfrp =
7270 hal_he_bfrp->f2p_info.tri_pad_bfrp;
7271 mac_bfrp_f2p[1].ul_cqi_rpt_tri_bfrp =
7272 hal_he_bfrp->f2p_info.ul_cqi_rpt_tri_bfrp;
7273 mac_bfrp_f2p[1].rf_gain_idx_bfrp =
7274 hal_he_bfrp->f2p_info.rf_gain_idx_bfrp;
7275 mac_bfrp_f2p[1].fix_gain_en_bfrp =
7276 hal_he_bfrp->f2p_info.fix_gain_en_bfrp;
7277 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7278 "==> _hal_max_ax_snd_cmd_bfrp_he_f2p[1] \n");
7279 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7280 "mac_bfrp_f2p[1].csi_len_bfrp = 0x%x \n",
7281 mac_bfrp_f2p[1].csi_len_bfrp);
7282 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7283 "mac_bfrp_f2p[1].tb_t_pe_bfrp = 0x%x \n",
7284 mac_bfrp_f2p[1].tb_t_pe_bfrp);
7285 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7286 "mac_bfrp_f2p[1].tri_pad_bfrp = 0x%x \n",
7287 mac_bfrp_f2p[1].tri_pad_bfrp);
7288 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7289 "mac_bfrp_f2p[1].ul_cqi_rpt_tri_bfrp = 0x%x \n",
7290 mac_bfrp_f2p[1].ul_cqi_rpt_tri_bfrp);
7291 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7292 "mac_bfrp_f2p[1].rf_gain_idx_bfrp = 0x%x \n",
7293 mac_bfrp_f2p[1].rf_gain_idx_bfrp);
7294 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7295 "mac_bfrp_f2p[1].fix_gain_en_bfrp = 0x%x \n",
7296 mac_bfrp_f2p[1].fix_gain_en_bfrp);
7297 }
7298 }
7299
7300
7301 /* 3. WD Content */
_hal_max_ax_snd_cmd_wd(struct mac_ax_snd_wd_para * mac_wd,struct hal_snd_wd_para * hal_wd)7302 void _hal_max_ax_snd_cmd_wd(struct mac_ax_snd_wd_para *mac_wd,
7303 struct hal_snd_wd_para *hal_wd)
7304 {
7305 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "==> _hal_max_ax_snd_cmd_wd \n");
7306 mac_wd->txpktsize = hal_wd->txpktsize;
7307 mac_wd->ndpa_duration = hal_wd->ndpa_duration;
7308 mac_wd->datarate = hal_wd->datarate;
7309 mac_wd->macid = hal_wd->macid;
7310 mac_wd->force_txop = hal_wd->force_txop;
7311 mac_wd->data_bw = hal_wd->data_bw;
7312 mac_wd->gi_ltf = hal_wd->gi_ltf;
7313 mac_wd->data_er = hal_wd->data_er;
7314 mac_wd->data_dcm = hal_wd->data_dcm;
7315 mac_wd->data_stbc = hal_wd->data_stbc;
7316 mac_wd->data_ldpc = hal_wd->data_ldpc;
7317 mac_wd->data_bw_er = hal_wd->data_bw_er;
7318 mac_wd->multiport_id = hal_wd->multiport_id;
7319 mac_wd->mbssid = hal_wd->mbssid;
7320
7321 mac_wd->signaling_ta_pkt_sc = hal_wd->signaling_ta_pkt_sc;
7322 mac_wd->sw_define = hal_wd->sw_define;
7323 mac_wd->txpwr_ofset_type = hal_wd->txpwr_ofset_type;
7324 mac_wd->lifetime_sel = hal_wd->lifetime_sel;
7325 mac_wd->stf_mode = hal_wd->stf_mode;
7326 mac_wd->disdatafb = hal_wd->disdatafb;
7327 mac_wd->data_txcnt_lmt_sel = hal_wd->data_txcnt_lmt_sel;
7328 mac_wd->data_txcnt_lmt = hal_wd->data_txcnt_lmt;
7329 mac_wd->sifs_tx = hal_wd->sifs_tx;
7330 mac_wd->snd_pkt_sel = hal_wd->snd_pkt_sel;
7331 mac_wd->ndpa = hal_wd->ndpa;
7332
7333 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->txpktsize = 0x%x \n", mac_wd->txpktsize);
7334 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->ndpa_duration = 0x%x \n", mac_wd->ndpa_duration);
7335 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->datarate = 0x%x \n", mac_wd->datarate);
7336 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "mac_wd->macid = 0x%x \n", mac_wd->macid);
7337 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->force_txop = 0x%x \n", mac_wd->force_txop);
7338 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_bw = 0x%x \n", mac_wd->data_bw);
7339 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->gi_ltf = 0x%x \n", mac_wd->gi_ltf);
7340 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_er = 0x%x \n", mac_wd->data_er);
7341
7342 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_dcm = 0x%x \n", mac_wd->data_dcm);
7343 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_stbc = 0x%x \n", mac_wd->data_stbc);
7344 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_ldpc = 0x%x \n", mac_wd->data_ldpc);
7345 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_bw_er = 0x%x \n", mac_wd->data_bw_er);
7346 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->multiport_id = 0x%x \n", mac_wd->multiport_id);
7347 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->mbssid = 0x%x \n", mac_wd->mbssid);
7348 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->signaling_ta_pkt_sc = 0x%x \n", mac_wd->signaling_ta_pkt_sc);
7349 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->sw_define = 0x%x \n", mac_wd->sw_define);
7350
7351 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->txpwr_ofset_type = 0x%x \n", mac_wd->txpwr_ofset_type);
7352 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->lifetime_sel = 0x%x \n", mac_wd->lifetime_sel);
7353 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->stf_mode = 0x%x \n", mac_wd->stf_mode);
7354 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->disdatafb = 0x%x \n", mac_wd->disdatafb);
7355 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_txcnt_lmt_sel = 0x%x \n", mac_wd->data_txcnt_lmt_sel);
7356 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_txcnt_lmt = 0x%x \n", mac_wd->data_txcnt_lmt);
7357 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->sifs_tx = 0x%x \n", mac_wd->sifs_tx);
7358 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "mac_wd->snd_pkt_sel = 0x%x \n", mac_wd->snd_pkt_sel);
7359 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "mac_wd->ndpa = 0x%x \n", mac_wd->ndpa);
7360 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "<== _hal_max_ax_snd_cmd_wd \n");
7361 }
7362
7363
7364 enum rtw_hal_status
hal_mac_ax_send_fw_snd(struct hal_info_t * hal_info,struct hal_ax_fwcmd_snd * hal_cmd)7365 hal_mac_ax_send_fw_snd(struct hal_info_t *hal_info,
7366 struct hal_ax_fwcmd_snd *hal_cmd)
7367 {
7368 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
7369 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7370 struct mac_ax_fwcmd_snd snd_cmd = {0};
7371 u8 i = 0, he = 0, sta_nr = 0;
7372
7373 /* 1. COMMAND Common */
7374 snd_cmd.frexgtype = hal_cmd->frame_ex_type;
7375 snd_cmd.bfrp0_user_num = hal_cmd->bfrp0_sta_nr;
7376 snd_cmd.bfrp1_user_num = hal_cmd->bfrp1_sta_nr;
7377 for (i = 0; i < HAL_MAX_HE_SND_STA_NUM; i++) {
7378 snd_cmd.macid[i] = (u8)hal_cmd->macid[i];
7379 }
7380
7381 he = (hal_cmd->frame_ex_type >= HAL_FEXG_TYPE_AX_SU) ? 1 : 0;
7382
7383 if (hal_cmd->frame_ex_type == HAL_FEXG_TYPE_AX_SU) {
7384 sta_nr = 1;
7385 } else {
7386 sta_nr = he ? (hal_cmd->bfrp0_sta_nr + hal_cmd->bfrp1_sta_nr) :
7387 (hal_cmd->frame_ex_type - HAL_FEXG_TYPE_AC_SU + 1);
7388 }
7389
7390 /* 2. NDPA Content */
7391 _hal_max_ax_snd_cmd_ndpa(&snd_cmd.pndpa, &hal_cmd->ndpa,
7392 he, sta_nr);
7393 /* 3. BFRP Content */
7394 if (he) {
7395 _hal_max_ax_snd_cmd_bfrp_he(&snd_cmd.pbfrp, &hal_cmd->bfrp,
7396 hal_cmd->bfrp0_sta_nr, hal_cmd->bfrp1_sta_nr);
7397 _hal_max_ax_snd_cmd_bfrp_he_f2p(snd_cmd.f2p, &hal_cmd->bfrp,
7398 hal_cmd->bfrp0_sta_nr, hal_cmd->bfrp1_sta_nr);
7399 } else {
7400 _hal_max_ax_snd_cmd_bfrp_vht(&snd_cmd.pbfrp, &hal_cmd->bfrp,
7401 (sta_nr - 1));
7402 }
7403 /* 4. WD Content */
7404 /* 4-1 NDPA */
7405 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "NDPA WD: \n");
7406 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[0], &hal_cmd->wd[0]);
7407 /* 4-2 NDP */
7408 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "NDP WD: \n");
7409 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[1], &hal_cmd->wd[1]);
7410 /* 4-3 BFRP*/
7411 if (he) {
7412 if (hal_cmd->bfrp0_sta_nr) {
7413 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "HE BFRP-1 WD: \n");
7414 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[2],
7415 &hal_cmd->wd[2]);
7416 }
7417 if (hal_cmd->bfrp1_sta_nr) {
7418 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "HE BFRP-2 WD: \n");
7419 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[3],
7420 &hal_cmd->wd[3]);
7421 }
7422 } else {
7423 for (i = 0; i < (sta_nr - 1)&&(i < HAL_MAX_VHT_BFRP_NUM);
7424 i++) {
7425 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "VHT BFRP %d WD: \n", i);
7426 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[2 + i],
7427 &hal_cmd->wd[2 + i]);
7428 }
7429 }
7430
7431 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.macid[0] = 0x%x \n", snd_cmd.macid[0]);
7432 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.bfrp0_user_num = 0x%x \n", snd_cmd.bfrp0_user_num);
7433 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.bfrp1_user_num = 0x%x \n", snd_cmd.bfrp1_user_num);
7434 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.mode = 0x%x \n", snd_cmd.mode);
7435 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.frexgtype = 0x%x \n", snd_cmd.frexgtype);
7436 hstatus = mac->ops->set_snd_para(mac, &snd_cmd);
7437 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] hal_mac_ax_send_fw_snd hstatus = 0x%x\n", hstatus);
7438
7439 return hstatus;
7440 }
7441
7442
7443
7444 enum rtw_hal_status
rtw_hal_mac_tx_mode_sel(struct hal_info_t * hal_info,u8 fw_tx,u8 txop_wmm_en_bm)7445 rtw_hal_mac_tx_mode_sel(struct hal_info_t *hal_info, u8 fw_tx, u8 txop_wmm_en_bm)
7446 {
7447 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7448
7449 struct mac_ax_mac_tx_mode_sel mode_sel = {0};
7450
7451 if (fw_tx)
7452 mode_sel.sw_mode_band0_en = 1;
7453 if (txop_wmm_en_bm & BIT(0))
7454 mode_sel.txop_rot_wmm0_en = 1;
7455 if (txop_wmm_en_bm & BIT(1))
7456 mode_sel.txop_rot_wmm1_en = 1;
7457 if (txop_wmm_en_bm & BIT(2))
7458 mode_sel.txop_rot_wmm2_en = 1;
7459 if (txop_wmm_en_bm & BIT(3))
7460 mode_sel.txop_rot_wmm3_en = 1;
7461
7462 mac->ops->tx_mode_sel(mac, &mode_sel);
7463 return RTW_HAL_STATUS_SUCCESS;
7464 }
7465
rtw_hal_mac_process_c2h(void * hal,struct rtw_c2h_info * c2h)7466 u32 rtw_hal_mac_process_c2h(void *hal, struct rtw_c2h_info *c2h)
7467 {
7468 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
7469 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7470 struct mac_ax_ccxrpt mac_ccx = {0};
7471 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
7472 #ifdef RTW_WKARD_CCX_RPT_LIMIT_CTRL
7473 u32 retry_limit = 32;
7474 #endif
7475 u32 retid = 0;
7476
7477 hal_status = mac->ops->get_c2h_event(mac, c2h, (enum phl_msg_evt_id *)&retid, (u8 *)&mac_ccx);
7478 /*PHL_INFO("%s, hal_status=%d, retid=%d\n", __func__, hal_status, retid);*/
7479
7480 if (hal_status == RTW_HAL_STATUS_SUCCESS && (retid == MSG_EVT_CCX_REPORT_TX_OK || retid == MSG_EVT_CCX_REPORT_TX_FAIL)) {
7481 #if 0
7482 PHL_INFO("%s, mac_ccx.tx_state=%d\n", __func__, mac_ccx.tx_state);
7483 PHL_INFO("%s, mac_ccx.sw_define=%d\n", __func__, mac_ccx.sw_define);
7484 PHL_INFO("%s, mac_ccx.macid=%d\n", __func__, mac_ccx.macid);
7485 PHL_INFO("%s, mac_ccx.pkt_ok_num=%d\n", __func__, mac_ccx.pkt_ok_num);
7486 PHL_INFO("%s, mac_ccx.data_txcnt=%d\n", __func__, mac_ccx.data_txcnt);
7487 #endif
7488
7489 #ifdef RTW_WKARD_CCX_RPT_LIMIT_CTRL
7490 if (hal_info->hal_com->spe_pkt_cnt_lmt)
7491 retry_limit = hal_info->hal_com->spe_pkt_cnt_lmt;
7492
7493 if (retid == MSG_EVT_CCX_REPORT_TX_FAIL && mac_ccx.data_txcnt != retry_limit)
7494 retid = 0;
7495 #endif
7496 }
7497 return retid;
7498 }
7499
7500 enum rtw_hal_status
rtw_hal_mac_f2p_test_cmd(struct hal_info_t * hal_info,struct mp_mac_ax_f2p_test_para * info,struct mp_mac_ax_f2p_wd * f2pwd,struct mp_mac_ax_f2p_tx_cmd * ptxcmd,u8 * psigb_addr)7501 rtw_hal_mac_f2p_test_cmd(struct hal_info_t *hal_info,
7502 struct mp_mac_ax_f2p_test_para *info,
7503 struct mp_mac_ax_f2p_wd *f2pwd,
7504 struct mp_mac_ax_f2p_tx_cmd *ptxcmd,
7505 u8 *psigb_addr)
7506 {
7507 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7508 u32 ret = RTW_HAL_STATUS_FAILURE;
7509
7510 if (mac->ops->f2p_test_cmd(mac, (void*)info, (void*)f2pwd, (void*)ptxcmd, psigb_addr) == MACSUCCESS)
7511 ret = RTW_HAL_STATUS_SUCCESS;
7512
7513 return ret;
7514 }
7515
7516 enum rtw_hal_status
rtw_hal_mac_write_pwr_ofst_mode(struct rtw_hal_com_t * hal_com,u8 band)7517 rtw_hal_mac_write_pwr_ofst_mode(struct rtw_hal_com_t *hal_com, u8 band)
7518 {
7519
7520 struct hal_info_t *hal_info = hal_com->hal_priv;
7521 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7522 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7523
7524 if (tpu->normal_mode_lock_en)
7525 return RTW_HAL_STATUS_FAILURE;
7526
7527 mac->ops->write_pwr_ofst_mode(mac, band, tpu);
7528
7529 return RTW_HAL_STATUS_SUCCESS;
7530 }
7531
7532 enum rtw_hal_status
rtw_hal_mac_write_pwr_ofst_bw(struct rtw_hal_com_t * hal_com,u8 band)7533 rtw_hal_mac_write_pwr_ofst_bw(struct rtw_hal_com_t *hal_com, u8 band)
7534 {
7535 struct hal_info_t *hal_info = hal_com->hal_priv;
7536 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7537 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7538
7539 if (tpu->normal_mode_lock_en)
7540 return RTW_HAL_STATUS_FAILURE;
7541
7542 mac->ops->write_pwr_ofst_bw(mac, band, tpu);
7543
7544 return RTW_HAL_STATUS_SUCCESS;
7545 }
7546
7547 enum rtw_hal_status
rtw_hal_mac_write_pwr_ref_reg(struct rtw_hal_com_t * hal_com,u8 band)7548 rtw_hal_mac_write_pwr_ref_reg(struct rtw_hal_com_t *hal_com, u8 band)
7549 {
7550 struct hal_info_t *hal_info = hal_com->hal_priv;
7551 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7552 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7553
7554 if (tpu->normal_mode_lock_en)
7555 return RTW_HAL_STATUS_FAILURE;
7556
7557 mac->ops->write_pwr_ref_reg(mac, band, tpu);
7558
7559 return RTW_HAL_STATUS_SUCCESS;
7560 }
7561
7562 enum rtw_hal_status
rtw_hal_mac_write_pwr_limit_en(struct rtw_hal_com_t * hal_com,u8 band)7563 rtw_hal_mac_write_pwr_limit_en(struct rtw_hal_com_t *hal_com, u8 band)
7564 {
7565 struct hal_info_t *hal_info = hal_com->hal_priv;
7566 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7567 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7568
7569 if (tpu->normal_mode_lock_en)
7570 return RTW_HAL_STATUS_FAILURE;
7571
7572 mac->ops->write_pwr_limit_en(mac, band, tpu);
7573
7574 return RTW_HAL_STATUS_SUCCESS;
7575 }
7576
7577 enum rtw_hal_status
rtw_hal_mac_set_pwr_lmt_en_val(struct rtw_hal_com_t * hal_com,u8 band,bool en_val)7578 rtw_hal_mac_set_pwr_lmt_en_val(struct rtw_hal_com_t *hal_com, u8 band, bool en_val)
7579 {
7580 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7581
7582 if (tpu->normal_mode_lock_en)
7583 return RTW_HAL_STATUS_FAILURE;
7584
7585 tpu->pwr_lmt_en = en_val;
7586
7587 return RTW_HAL_STATUS_SUCCESS;
7588 }
7589
7590 bool
rtw_hal_mac_get_pwr_lmt_en_val(struct rtw_hal_com_t * hal_com,u8 band)7591 rtw_hal_mac_get_pwr_lmt_en_val(struct rtw_hal_com_t *hal_com, u8 band)
7592 {
7593
7594 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7595
7596 return tpu->pwr_lmt_en;
7597 }
7598
7599 enum rtw_hal_status
rtw_hal_mac_set_tpu_mode(struct rtw_hal_com_t * hal_com,enum rtw_tpu_op_mode op_mode_new,u8 band)7600 rtw_hal_mac_set_tpu_mode(struct rtw_hal_com_t *hal_com,
7601 enum rtw_tpu_op_mode op_mode_new, u8 band)
7602 {
7603 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7604
7605 if (op_mode_new == TPU_DBG_MODE) {
7606 tpu->op_mode = TPU_DBG_MODE;
7607 tpu->normal_mode_lock_en = true;
7608 } else {
7609 tpu->op_mode = TPU_NORMAL_MODE;
7610 tpu->normal_mode_lock_en = false;
7611 }
7612
7613 return RTW_HAL_STATUS_SUCCESS;
7614 }
7615
7616 enum rtw_hal_status
rtw_hal_mac_write_pwr_limit_rua_reg(struct rtw_hal_com_t * hal_com,u8 band)7617 rtw_hal_mac_write_pwr_limit_rua_reg(struct rtw_hal_com_t *hal_com, u8 band)
7618 {
7619 struct hal_info_t *hal_info = hal_com->hal_priv;
7620 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7621 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7622
7623 if (tpu->normal_mode_lock_en)
7624 return RTW_HAL_STATUS_FAILURE;
7625
7626 mac->ops->write_pwr_limit_rua_reg(mac, band, tpu);
7627
7628 return RTW_HAL_STATUS_SUCCESS;
7629 }
7630
7631 enum rtw_hal_status
rtw_hal_mac_write_pwr_limit_reg(struct rtw_hal_com_t * hal_com,u8 band)7632 rtw_hal_mac_write_pwr_limit_reg(struct rtw_hal_com_t *hal_com, u8 band)
7633 {
7634 struct hal_info_t *hal_info = hal_com->hal_priv;
7635 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7636 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7637 struct rtw_tpu_pwr_imt_info *lmt = &tpu->rtw_tpu_pwr_imt_i;
7638
7639 if (tpu->normal_mode_lock_en)
7640 return RTW_HAL_STATUS_FAILURE;
7641
7642 mac->ops->write_pwr_limit_reg(mac, band, lmt);
7643
7644 return RTW_HAL_STATUS_SUCCESS;
7645 }
7646
7647 enum rtw_hal_status
rtw_hal_mac_write_pwr_by_rate_reg(struct rtw_hal_com_t * hal_com,u8 band)7648 rtw_hal_mac_write_pwr_by_rate_reg(struct rtw_hal_com_t *hal_com, u8 band)
7649 {
7650 struct hal_info_t *hal_info = hal_com->hal_priv;
7651 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7652 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7653 struct rtw_tpu_pwr_by_rate_info *by_rate = &tpu->rtw_tpu_pwr_by_rate_i;
7654
7655 if (tpu->normal_mode_lock_en)
7656 return RTW_HAL_STATUS_FAILURE;
7657
7658 mac->ops->write_pwr_by_rate_reg(mac, band, by_rate);
7659
7660 return RTW_HAL_STATUS_SUCCESS;
7661 }
7662
7663 enum rtw_hal_status
rtw_hal_mac_get_log_efuse_bt_size(struct rtw_hal_com_t * hal_com,u32 * val)7664 rtw_hal_mac_get_log_efuse_bt_size(struct rtw_hal_com_t *hal_com, u32 *val)
7665 {
7666 struct hal_info_t *hal_info = hal_com->hal_priv;
7667 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7668
7669 if (mac->ops->get_hw_value(mac,
7670 MAC_AX_HW_GET_BT_LOGICAL_EFUSE_SIZE, val) != MACSUCCESS){
7671 PHL_ERR("%s: Get bt efuse size fail!\n", __FUNCTION__);
7672 return RTW_HAL_STATUS_FAILURE;
7673 }
7674 PHL_INFO("%s: BT Efuse log size = %d!\n", __FUNCTION__, *val);
7675
7676 return RTW_HAL_STATUS_SUCCESS;
7677 }
7678
7679 enum rtw_hal_status
rtw_hal_mac_get_efuse_bt_mask_size(struct rtw_hal_com_t * hal_com,u32 * val)7680 rtw_hal_mac_get_efuse_bt_mask_size(struct rtw_hal_com_t *hal_com, u32 *val)
7681 {
7682 struct hal_info_t *hal_info = hal_com->hal_priv;
7683 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7684
7685 if(mac->ops->get_hw_value(mac,
7686 MAC_AX_HW_GET_BT_EFUSE_MASK_SIZE, val) != MACSUCCESS)
7687 return RTW_HAL_STATUS_FAILURE;
7688
7689 PHL_INFO("%s: bt efuse mask size = %d\n", __FUNCTION__, *val);
7690 return RTW_HAL_STATUS_SUCCESS;
7691 }
7692
7693 enum rtw_hal_status
rtw_hal_mac_write_log_efuse_bt_map(struct rtw_hal_com_t * hal_com,u8 * map,u32 map_size,u8 * mask,u32 mask_size)7694 rtw_hal_mac_write_log_efuse_bt_map(struct rtw_hal_com_t *hal_com,
7695 u8 *map,
7696 u32 map_size,
7697 u8 *mask,
7698 u32 mask_size)
7699 {
7700 struct hal_info_t *hal_info = hal_com->hal_priv;
7701 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7702 struct mac_ax_pg_efuse_info info;
7703 enum rtw_hal_status status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
7704 u8 *tmp_map = NULL;
7705 u8 *tmp_mask = NULL;
7706
7707 tmp_map = _os_mem_alloc(hal_com->drv_priv, map_size);
7708 if(tmp_map == NULL) {
7709 PHL_WARN("%s: Allocate pg map buffer fail!\n", __FUNCTION__);
7710 status = RTW_HAL_STATUS_RESOURCE;
7711 goto err_mem_tmp_map;
7712 }
7713
7714 tmp_mask = _os_mem_alloc(hal_com->drv_priv, mask_size);
7715 if(tmp_mask == NULL) {
7716 PHL_WARN("%s: Allocate pg mask buffer fail!\n", __FUNCTION__);
7717 status = RTW_HAL_STATUS_RESOURCE;
7718 goto err_mem_tmp_mask;
7719 }
7720
7721 /* Copy efuse map to tmp_map buffer */
7722 _os_mem_cpy(hal_com->drv_priv, tmp_map, map, map_size);
7723
7724 /* Copy efuse mask to tmp_mask buffer */
7725 _os_mem_cpy(hal_com->drv_priv, tmp_mask, mask, mask_size);
7726
7727
7728 info.efuse_map = tmp_map;
7729 info.efuse_map_size = map_size;
7730 info.efuse_mask = tmp_mask;
7731 info.efuse_mask_size= mask_size;
7732
7733 if (mac->ops->pg_efuse_by_map_bt(mac,
7734 &info,
7735 MAC_AX_EFUSE_R_DRV) != MACSUCCESS) {
7736 PHL_INFO("%s: BT PG Fail!\n", __FUNCTION__);
7737 status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
7738 }
7739 else {
7740 PHL_INFO("%s: BT PG ok!\n", __FUNCTION__);
7741 status = RTW_HAL_STATUS_SUCCESS;
7742 }
7743 _os_mem_free(hal_com->drv_priv, tmp_map, map_size);
7744 _os_mem_free(hal_com->drv_priv, tmp_mask, mask_size);
7745
7746 return status;
7747
7748 err_mem_tmp_mask:
7749 _os_mem_free(hal_com->drv_priv, tmp_mask, mask_size);
7750
7751 err_mem_tmp_map:
7752 _os_mem_free(hal_com->drv_priv, tmp_map, map_size);
7753
7754 return status;
7755 }
7756
7757 enum rtw_hal_status
rtw_hal_mac_read_log_efuse_bt_map(struct rtw_hal_com_t * hal_com,u8 * map)7758 rtw_hal_mac_read_log_efuse_bt_map(struct rtw_hal_com_t *hal_com, u8 *map)
7759 {
7760 struct hal_info_t *hal_info = hal_com->hal_priv;
7761 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7762
7763 if (mac->ops->dump_log_efuse_bt(mac,
7764 MAC_AX_EFUSE_PARSER_MAP,
7765 #ifdef RTW_WKARD_EFUSE_OPERATION
7766 MAC_AX_EFUSE_R_DRV,
7767 #else
7768 MAC_AX_EFUSE_R_AUTO,
7769 #endif
7770 map
7771 ) != MACSUCCESS) {
7772 PHL_INFO("%s: Dump bt logical efuse fail!\n", __FUNCTION__);
7773 return RTW_HAL_STATUS_FAILURE;
7774 }
7775
7776 PHL_INFO("%s: Dump bt logical efuse ok!\n", __FUNCTION__);
7777 return RTW_HAL_STATUS_SUCCESS;
7778 }
7779
7780 enum rtw_hal_status
rtw_hal_mac_get_efuse_bt_avl(struct rtw_hal_com_t * hal_com,u32 * val)7781 rtw_hal_mac_get_efuse_bt_avl(struct rtw_hal_com_t *hal_com, u32 *val)
7782 {
7783 struct hal_info_t *hal_info = hal_com->hal_priv;
7784 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7785
7786 if (mac->ops->get_efuse_avl_size_bt(mac, val) != MACSUCCESS)
7787 return RTW_HAL_STATUS_FAILURE;
7788
7789 PHL_INFO("%s\n", __FUNCTION__);
7790 return RTW_HAL_STATUS_SUCCESS;
7791 }
7792
7793 enum rtw_hal_status
rtw_hal_mac_get_efuse_bt_size(struct rtw_hal_com_t * hal_com,u32 * val)7794 rtw_hal_mac_get_efuse_bt_size(struct rtw_hal_com_t *hal_com, u32 *val)
7795 {
7796 struct hal_info_t *hal_info = hal_com->hal_priv;
7797 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7798
7799 if (mac->ops->get_hw_value(mac,
7800 MAC_AX_HW_GET_BT_EFUSE_SIZE, val) != MACSUCCESS){
7801 PHL_ERR("%s: Get efuse bt size fail!\n", __FUNCTION__);
7802 return RTW_HAL_STATUS_FAILURE;
7803 }
7804 PHL_INFO("%s: Efuse size = %d!\n", __FUNCTION__, *val);
7805
7806 return RTW_HAL_STATUS_SUCCESS;
7807 }
7808
7809 enum rtw_hal_status
rtw_hal_mac_set_mu_edca(struct rtw_hal_com_t * hal_com,u8 band,u8 ac,u16 timer,u8 cw_min,u8 cw_max,u8 aifs)7810 rtw_hal_mac_set_mu_edca(struct rtw_hal_com_t *hal_com, u8 band, u8 ac,
7811 u16 timer, u8 cw_min, u8 cw_max, u8 aifs)
7812 {
7813 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
7814 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7815 struct mac_ax_muedca_param edca = {0};
7816 u32 err = 0;
7817
7818 edca.band = band;
7819 edca.ac = ac;
7820 edca.aifs_us = aifs;
7821 edca.ecw_min = cw_min;
7822 edca.ecw_max = cw_max;
7823 edca.muedca_timer_32us = timer;
7824 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_MUEDCA_PARAM, &edca);
7825 if (err)
7826 return RTW_HAL_STATUS_FAILURE;
7827
7828 return RTW_HAL_STATUS_SUCCESS;
7829 }
7830
7831 enum rtw_hal_status
rtw_hal_mac_set_mu_edca_ctrl(struct rtw_hal_com_t * hal_com,u8 band,u8 wmm,u8 set)7832 rtw_hal_mac_set_mu_edca_ctrl(struct rtw_hal_com_t *hal_com,
7833 u8 band, u8 wmm, u8 set)
7834 {
7835 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
7836 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7837 struct mac_ax_muedca_cfg cfg = {0};
7838 u32 err = 0;
7839
7840 cfg.band = band;
7841 cfg.wmm_sel = wmm;
7842 cfg.countdown_en = set;
7843 cfg.tb_update_en = set;
7844 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_MUEDCA_CTRL, &cfg);
7845 if (err)
7846 return RTW_HAL_STATUS_FAILURE;
7847
7848 return RTW_HAL_STATUS_SUCCESS;
7849 }
7850
rtw_hal_mac_led_set_ctrl_mode(struct hal_info_t * hal_info,enum mac_ax_led_mode mode,u8 led_id)7851 enum rtw_hal_status rtw_hal_mac_led_set_ctrl_mode(struct hal_info_t *hal_info,
7852 enum mac_ax_led_mode mode,
7853 u8 led_id)
7854 {
7855 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7856
7857 if (mac->ops->set_led_mode(mac, mode, led_id) != MACSUCCESS)
7858 return RTW_HAL_STATUS_FAILURE;
7859
7860 return RTW_HAL_STATUS_SUCCESS;
7861 }
7862
rtw_hal_mac_led_ctrl(struct hal_info_t * hal_info,u8 high,u8 led_id)7863 enum rtw_hal_status rtw_hal_mac_led_ctrl(struct hal_info_t *hal_info, u8 high,
7864 u8 led_id)
7865 {
7866 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7867
7868 if (mac->ops->led_ctrl(mac, high, led_id) != MACSUCCESS)
7869 return RTW_HAL_STATUS_FAILURE;
7870
7871 return RTW_HAL_STATUS_SUCCESS;
7872 }
7873
rtw_hal_mac_sw_gpio_ctrl(struct hal_info_t * hal_info,u8 high,u8 gpio)7874 enum rtw_hal_status rtw_hal_mac_sw_gpio_ctrl(struct hal_info_t *hal_info, u8 high,
7875 u8 gpio)
7876 {
7877 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7878
7879 if (mac->ops->sw_gpio_ctrl(mac, high, gpio) != MACSUCCESS)
7880 return RTW_HAL_STATUS_FAILURE;
7881
7882 return RTW_HAL_STATUS_SUCCESS;
7883 }
7884
rtw_hal_mac_set_sw_gpio_mode(struct hal_info_t * hal_info,enum rtw_gpio_mode mode,u8 gpio)7885 enum rtw_hal_status rtw_hal_mac_set_sw_gpio_mode(struct hal_info_t *hal_info, enum rtw_gpio_mode mode,
7886 u8 gpio)
7887 {
7888 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7889
7890 if (mac->ops->set_sw_gpio_mode(mac, mode, gpio) != MACSUCCESS)
7891 return RTW_HAL_STATUS_FAILURE;
7892
7893 return RTW_HAL_STATUS_SUCCESS;
7894 }
7895
rtw_hal_mac_get_wl_dis_val(struct hal_info_t * hal_info,u8 * val)7896 enum rtw_hal_status rtw_hal_mac_get_wl_dis_val(struct hal_info_t *hal_info, u8 *val)
7897 {
7898 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7899
7900 if (mac->ops->get_wl_dis_val(mac, val) != MACSUCCESS)
7901 return RTW_HAL_STATUS_FAILURE;
7902
7903 return RTW_HAL_STATUS_SUCCESS;
7904 }
7905
7906 enum rtw_hal_status
rtw_hal_mac_pcie_trx_mit(struct hal_info_t * hal_info,struct mac_ax_pcie_trx_mitigation * mit_info)7907 rtw_hal_mac_pcie_trx_mit(struct hal_info_t *hal_info,
7908 struct mac_ax_pcie_trx_mitigation *mit_info)
7909 {
7910 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7911
7912 if (MACSUCCESS !=
7913 mac->ops->set_hw_value(mac, MAX_AX_HW_PCIE_MIT, mit_info))
7914 return RTW_HAL_STATUS_FAILURE;
7915
7916 return RTW_HAL_STATUS_SUCCESS;
7917 }
7918
7919 enum rtw_hal_status
rtw_hal_mac_read_efuse_bt_hidden(struct rtw_hal_com_t * hal_com,u32 addr,u32 size,u8 * val)7920 rtw_hal_mac_read_efuse_bt_hidden(struct rtw_hal_com_t *hal_com, u32 addr, u32 size, u8 *val)
7921 {
7922 struct hal_info_t *hal_info = hal_com->hal_priv;
7923 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7924
7925 if (mac->ops->read_efuse(mac, addr, size, val, MAC_AX_EFUSE_BANK_BT) != MACSUCCESS)
7926 return RTW_HAL_STATUS_FAILURE;
7927
7928 PHL_INFO("%s\n", __FUNCTION__);
7929 return RTW_HAL_STATUS_SUCCESS;
7930 }
7931
7932 enum rtw_hal_status
rtw_hal_mac_write_efuse_bt_hidden(struct rtw_hal_com_t * hal_com,u32 addr,u8 val)7933 rtw_hal_mac_write_efuse_bt_hidden(struct rtw_hal_com_t *hal_com, u32 addr, u8 val)
7934 {
7935 struct hal_info_t *hal_info = hal_com->hal_priv;
7936 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7937
7938 u8 tmp_value;
7939
7940 if (mac->ops->read_efuse(mac, addr, 1, &tmp_value, MAC_AX_EFUSE_BANK_BT) != MACSUCCESS) {
7941 PHL_INFO("%s read bt efuse hideen block fail.\n", __FUNCTION__);
7942 return RTW_HAL_STATUS_FAILURE;
7943 }
7944
7945 if(tmp_value != 0xFF) {
7946 PHL_INFO("%s bt efuse hidden offset = 0x%x has value = 0x%x.\n", __FUNCTION__, addr, tmp_value);
7947 return RTW_HAL_STATUS_FAILURE;
7948 }
7949
7950 if (mac->ops->write_efuse(mac, addr, val, MAC_AX_EFUSE_BANK_BT) != MACSUCCESS) {
7951 PHL_INFO("%s write bt efuse hideen block fail.\n", __FUNCTION__);
7952 return RTW_HAL_STATUS_FAILURE;
7953 }
7954
7955 PHL_INFO("%s\n", __FUNCTION__);
7956 return RTW_HAL_STATUS_SUCCESS;
7957 }
7958
7959 enum rtw_hal_status
rtw_hal_mac_tsf_sync(struct hal_info_t * hal_info,u8 from_port,u8 to_port,enum phl_band_idx band,s32 sync_offset_tu,enum hal_tsf_sync_act action)7960 rtw_hal_mac_tsf_sync(struct hal_info_t *hal_info,
7961 u8 from_port, u8 to_port, enum phl_band_idx band,
7962 s32 sync_offset_tu, enum hal_tsf_sync_act action)
7963 {
7964 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7965 enum mac_ax_tsf_sync_act mac_action = MAC_AX_TSF_SYNC_NOW_ONCE;
7966 s32 sync_offset_unit = 0;/* for halmac API use, unit is 32us */
7967
7968 switch (action){
7969 case HAL_TSF_SYNC_NOW_ONCE :
7970 mac_action = MAC_AX_TSF_SYNC_NOW_ONCE;
7971 break;
7972 case HAL_TSF_EN_SYNC_AUTO :
7973 mac_action = MAC_AX_TSF_EN_SYNC_AUTO;
7974 break;
7975 case HAL_TSF_DIS_SYNC_AUTO :
7976 mac_action = MAC_AX_TSF_DIS_SYNC_AUTO;
7977 break;
7978 default :
7979 PHL_ERR("Unknown tsf sync action %d\n", action);
7980 goto _error;
7981 }
7982
7983 /* covert TU to unit(unit is 32us, 1TU=1024us=32*32us) */
7984 sync_offset_unit = sync_offset_tu * 32;
7985
7986 if (mac->ops->tsf_sync(mac, from_port, to_port,
7987 sync_offset_unit, mac_action) == MACSUCCESS)
7988 return RTW_HAL_STATUS_SUCCESS;
7989 _error:
7990 return RTW_HAL_STATUS_FAILURE;
7991 }
7992
7993 /**
7994 * rtw_hal_mac_get_sec_cam() - get the security cam raw data from HW
7995 * @hal_info: struct hal_info_t *
7996 * @num: How many cam you wnat to dump from the first one.
7997 * @buf: ptr to buffer which store the content from HW.
7998 * If buf is NULL, use console as debug path.
7999 * @size Size of allocated memroy for @buf.
8000 * The size should be @num * size of security cam offset(0x20).
8001 *
8002 * Return RTW_HAL_STATUS_SUCCESS when function successfully works,
8003 * otherwise, return RTW_HAL_STATUS_FAILURE.
8004 */
8005 enum rtw_hal_status
rtw_hal_mac_get_sec_cam(struct hal_info_t * hal_info,u16 num,u8 * buf,u16 size)8006 rtw_hal_mac_get_sec_cam(struct hal_info_t *hal_info, u16 num, u8 *buf, u16 size)
8007 {
8008 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8009 int i = 0;
8010 /* ToDO: fix the magic number later */
8011 u8 sec_cam_offset_sz = 0x20;
8012
8013 if (buf == NULL) {
8014 /* to console */
8015 for (i = 0; i < num; i++) {
8016 PHL_INFO("======= SEC CAM (%d)DUMP =======\n", i);
8017 mac_mem_dump(mac, MAC_AX_MEM_SECURITY_CAM, i*sec_cam_offset_sz\
8018 , NULL, sec_cam_offset_sz, 0);
8019 PHL_INFO("\n");
8020 }
8021 } else {
8022 /* to buffer */
8023 if (size < sec_cam_offset_sz*num) {
8024 PHL_ERR("%s buf size is not enough to dump security cam\n", __func__);
8025 return RTW_HAL_STATUS_FAILURE;
8026 }
8027
8028 for (i = 0; i < num; i++)
8029 mac_mem_dump(mac, MAC_AX_MEM_SECURITY_CAM, i*sec_cam_offset_sz\
8030 , buf + (i*sec_cam_offset_sz), sec_cam_offset_sz, 1);
8031 }
8032 return RTW_HAL_STATUS_SUCCESS;
8033 }
8034
8035 /**
8036 * rtw_hal_mac_get_addr_cam() - get the address cam raw data from HW
8037 * @hal_info: struct hal_info_t *
8038 * @num: How many cam you wnat to dump from the first one.
8039 * @buf: ptr to buffer which store the content from HW.
8040 * If buf is NULL, use console as debug path.
8041 * @size Size of allocated memroy for @buf.
8042 * The size should be @num * size of Addr cam offset(0x40).
8043 *
8044 * Return RTW_HAL_STATUS_SUCCESS when function successfully works,
8045 * otherwise, return RTW_HAL_STATUS_FAILURE.
8046 */
8047 enum rtw_hal_status
rtw_hal_mac_get_addr_cam(struct hal_info_t * hal_info,u16 num,u8 * buf,u16 size)8048 rtw_hal_mac_get_addr_cam(struct hal_info_t *hal_info, u16 num, u8 *buf, u16 size)
8049 {
8050 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8051 int i = 0;
8052 /* ToDO: fix the magic number later */
8053 u8 addr_cam_offset_sz = 0x40;
8054
8055 if (buf == NULL) {
8056 /* to console */
8057 for (i = 0; i < num; i++) {
8058 PHL_INFO("======= ADDR CAM (%d)DUMP =======\n", i);
8059 mac_mem_dump(mac, MAC_AX_MEM_ADDR_CAM, i*addr_cam_offset_sz\
8060 , NULL, addr_cam_offset_sz, 0);
8061 PHL_INFO("\n");
8062 }
8063 } else {
8064 /* to buffer */
8065 if (size < addr_cam_offset_sz*num) {
8066 PHL_ERR("%s buf size is not enough to dump addr cam\n", __func__);
8067 return RTW_HAL_STATUS_FAILURE;
8068 }
8069
8070 for (i = 0; i < num; i++)
8071 mac_mem_dump(mac, MAC_AX_MEM_ADDR_CAM, i*addr_cam_offset_sz\
8072 , buf + (i*addr_cam_offset_sz), addr_cam_offset_sz, 1);
8073
8074 }
8075 return RTW_HAL_STATUS_SUCCESS;
8076 }
8077
rtw_hal_mac_get_tsf(struct hal_info_t * hal,u8 * port,u32 * tsf_h,u32 * tsf_l)8078 enum rtw_hal_status rtw_hal_mac_get_tsf(struct hal_info_t *hal, u8 *port,
8079 u32 *tsf_h, u32 *tsf_l)
8080 {
8081 struct mac_ax_adapter *mac = hal_to_mac(hal);
8082 struct mac_ax_ops *hal_mac_ops = mac->ops;
8083 struct mac_ax_port_tsf val = {0};
8084
8085 val.port = *port;
8086 if (hal_mac_ops->get_hw_value(mac, MAC_AX_HW_GET_TSF, &val))
8087 return RTW_HAL_STATUS_FAILURE;
8088 *tsf_h = val.tsf_h;
8089 *tsf_l = val.tsf_l;
8090 return RTW_HAL_STATUS_SUCCESS;
8091 }
8092
rtw_hal_mac_cfg_txhci(struct hal_info_t * hal,u8 en)8093 enum rtw_hal_status rtw_hal_mac_cfg_txhci(struct hal_info_t *hal, u8 en)
8094 {
8095 struct mac_ax_adapter *mac = hal_to_mac(hal);
8096 struct mac_ax_ops *hal_mac_ops = mac->ops;
8097 enum mac_ax_func_sw mac_en;
8098 u32 ret = 0;
8099
8100 if (en)
8101 mac_en = MAC_AX_FUNC_EN;
8102 else
8103 mac_en = MAC_AX_FUNC_DIS;
8104
8105 ret = hal_mac_ops->intf_ops->ctrl_txhci(mac, mac_en);
8106
8107 return (ret == MACSUCCESS) ?
8108 (RTW_HAL_STATUS_SUCCESS):(RTW_HAL_STATUS_FAILURE);
8109 }
8110
rtw_hal_mac_cfg_rxhci(struct hal_info_t * hal,u8 en)8111 enum rtw_hal_status rtw_hal_mac_cfg_rxhci(struct hal_info_t *hal, u8 en)
8112 {
8113 struct mac_ax_adapter *mac = hal_to_mac(hal);
8114 struct mac_ax_ops *hal_mac_ops = mac->ops;
8115 enum mac_ax_func_sw mac_en;
8116 u32 ret = 0;
8117
8118 if (en)
8119 mac_en = MAC_AX_FUNC_EN;
8120 else
8121 mac_en = MAC_AX_FUNC_DIS;
8122
8123 ret = hal_mac_ops->intf_ops->ctrl_rxhci(mac, mac_en);
8124
8125 return (ret == MACSUCCESS) ?
8126 (RTW_HAL_STATUS_SUCCESS):(RTW_HAL_STATUS_FAILURE);
8127 }
8128
8129 #ifdef CONFIG_MCC_SUPPORT
_hal_mac_mcc_fill_role_info(struct rtw_phl_mcc_role * mcc_role,struct mac_ax_mcc_role * info)8130 void _hal_mac_mcc_fill_role_info(struct rtw_phl_mcc_role *mcc_role,
8131 struct mac_ax_mcc_role *info)
8132 {
8133 struct rtw_phl_mcc_policy_info *policy = &mcc_role->policy;
8134
8135 if (mcc_role->bt_role) {
8136 info->group = mcc_role->group;
8137 info->btc_in_2g = true;
8138 info->duration = policy->dur_info.dur;
8139 } else {
8140 info->macid = mcc_role->macid;
8141 info->central_ch_seg0 = mcc_role->chandef->center_ch;
8142 info->central_ch_seg1 = (u8)mcc_role->chandef->center_freq2;
8143 info->primary_ch = mcc_role->chandef->chan;
8144 info->bandwidth = mcc_role->chandef->bw;
8145 info->group = mcc_role->group;
8146 info->c2h_rpt = policy->c2h_rpt;
8147 info->dis_tx_null = policy->dis_tx_null;
8148 info->dis_sw_retry = policy->dis_sw_retry;
8149 info->in_curr_ch = policy->in_curr_ch;
8150 info->sw_retry_count = policy->sw_retry_count;
8151 info->tx_null_early= policy->tx_null_early;
8152 info->duration = policy->dur_info.dur;
8153 info->courtesy_en = policy->courtesy_en;
8154 info->courtesy_num = policy->courtesy_num;
8155 info->courtesy_target = policy->courtesy_target;
8156 }
8157 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): macid(%d), central_ch_seg0(%d), central_ch_seg1(%d)\n",
8158 info->macid, info->central_ch_seg0, info->central_ch_seg1);
8159 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): primary_ch(%d), bandwidth(%d), group(%d), c2h_rpt(%d)\n",
8160 info->primary_ch, info->bandwidth, info->group, info->c2h_rpt);
8161 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): dis_tx_null(%d), dis_sw_retry(%d), in_curr_ch(%d)\n",
8162 info->dis_tx_null, info->dis_sw_retry, info->in_curr_ch);
8163 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): sw_retry_count(%d), tx_null_early(%d), btc_in_2g(%d)\n",
8164 info->sw_retry_count, info->tx_null_early, info->btc_in_2g);
8165 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): duration(%d)\n",
8166 info->duration);
8167 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): courtesy_en(%d), courtesy_num(%d), courtesy_target(0x%x)\n",
8168 info->courtesy_en, info->courtesy_num, info->courtesy_target);
8169 }
8170
_hal_mac_mcc_fill_duration_info(struct rtw_phl_mcc_en_info * en_info,struct rtw_phl_mcc_bt_info * bt_info,struct mac_ax_mcc_duration_info * info)8171 void _hal_mac_mcc_fill_duration_info(struct rtw_phl_mcc_en_info *en_info,
8172 struct rtw_phl_mcc_bt_info *bt_info,
8173 struct mac_ax_mcc_duration_info *info)
8174 {
8175 info->group = en_info->mcc_role[0].group;
8176 info->btc_in_group = (bt_info->bt_dur > 0) ? 1 : 0;
8177 info->start_macid = en_info->mcc_role[en_info->ref_role_idx].macid;
8178 info->macid_x = en_info->mcc_role[0].macid;
8179 info->macid_y = en_info->mcc_role[1].macid;
8180 info->duration_x = en_info->mcc_role[0].policy.dur_info.dur;
8181 info->duration_y = en_info->mcc_role[1].policy.dur_info.dur;
8182 info->start_tsf_low = en_info->tsf_low;
8183 info->start_tsf_high = en_info->tsf_high;
8184 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_duration_info(): info->group(%d), btc_in_group(%d), start_macid(%d), macid_x(%d), macid_y(%d)\n",
8185 info->group, info->btc_in_group, info->start_macid,
8186 info->macid_x, info->macid_y);
8187 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_duration_info(): duration_x(%d), duration_y(%d), start_tsf(0x%08x %08x)\n",
8188 info->duration_x, info->duration_y, info->start_tsf_high,
8189 info->start_tsf_low);
8190 }
8191
_hal_mac_mcc_fill_start_info(u8 group,u8 macid,u32 tsf_high,u32 tsf_low,u8 btc_in_group,u8 old_group_action,u8 old_group,struct mac_ax_mcc_start * info)8192 void _hal_mac_mcc_fill_start_info(u8 group, u8 macid, u32 tsf_high, u32 tsf_low,
8193 u8 btc_in_group, u8 old_group_action, u8 old_group,
8194 struct mac_ax_mcc_start *info)
8195 {
8196 info->group = group;
8197 info->btc_in_group = btc_in_group;
8198 info->old_group_action = old_group_action;
8199 info->old_group = old_group;
8200 info->macid = macid;
8201 info->tsf_low = tsf_low;
8202 info->tsf_high = tsf_high;
8203 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_start_info(): info->group(%d), btc_in_group(%d), old_group_action(%d), old_group(%d), macid(%d), Tsf(0x%08x %08x)\n",
8204 info->group, info->btc_in_group, info->old_group_action,
8205 info->old_group, info->macid, info->tsf_high, info->tsf_low);
8206 }
8207
rtw_hal_mac_add_mcc(struct hal_info_t * hal,struct rtw_phl_mcc_role * mcc_role)8208 enum rtw_hal_status rtw_hal_mac_add_mcc(struct hal_info_t *hal,
8209 struct rtw_phl_mcc_role *mcc_role)
8210 {
8211 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8212 struct mac_ax_adapter *mac = hal_to_mac(hal);
8213 u32 mac_status;
8214 u16 loop_cnt = 0;
8215 struct mac_ax_mcc_role info = {0};
8216
8217 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_add_mcc()\n");
8218 if (mac == NULL)
8219 goto exit;
8220 _hal_mac_mcc_fill_role_info(mcc_role, &info);
8221 mac_status = mac->ops->add_mcc(mac, &info);
8222 if (mac_status != MACSUCCESS) {
8223 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_add_mcc(): fault, status = %d.\n",
8224 mac_status);
8225 goto exit;
8226 }
8227 do {
8228 if (mac->ops->check_add_mcc_done(mac, (u8)info.group) ==
8229 MACSUCCESS)
8230 break;
8231 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8232 loop_cnt++;
8233 } while (loop_cnt < POLLING_HALMAC_CNT);
8234
8235 if (loop_cnt < POLLING_HALMAC_CNT) {
8236 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_add_mcc(): polling ok, count(%d)\n",
8237 loop_cnt);
8238 hal_status = RTW_HAL_STATUS_SUCCESS;
8239 } else {
8240 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_add_mcc(): polling timeout\n");
8241 }
8242 exit:
8243 return hal_status;
8244 }
8245
rtw_hal_mac_start_mcc(struct hal_info_t * hal,u8 group,u8 macid,u32 tsf_high,u32 tsf_low,u8 btc_in_group,u8 old_group_action,u8 old_group)8246 enum rtw_hal_status rtw_hal_mac_start_mcc(struct hal_info_t *hal,
8247 u8 group, u8 macid, u32 tsf_high, u32 tsf_low,
8248 u8 btc_in_group, u8 old_group_action, u8 old_group)
8249 {
8250 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8251 struct mac_ax_adapter *mac = hal_to_mac(hal);
8252 struct mac_ax_mcc_start info = {0};
8253 u32 mac_status = MACSUCCESS;
8254 u16 loop_cnt = 0;
8255
8256 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_start_mcc(): group(%d), macid(%d) Start tsf(0x%08X %08X), btc_in_group(%d)\n",
8257 group, macid, tsf_high, tsf_low, btc_in_group);
8258 if (mac == NULL)
8259 goto exit;
8260 _hal_mac_mcc_fill_start_info(group, macid, tsf_high, tsf_low,
8261 btc_in_group, old_group_action,
8262 old_group, &info);
8263 mac_status = mac->ops->start_mcc(mac, &info);
8264 if (mac_status != MACSUCCESS) {
8265 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_start_mcc(): fault, status = %d.\n",
8266 mac_status);
8267 goto exit;
8268 }
8269 do {
8270 if (mac->ops->check_start_mcc_done(mac, group) ==
8271 MACSUCCESS)
8272 break;
8273 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8274 loop_cnt++;
8275 } while (loop_cnt < POLLING_HALMAC_CNT);
8276
8277 if (loop_cnt < POLLING_HALMAC_CNT) {
8278 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_start_mcc(): polling ok, count(%d)\n",
8279 loop_cnt);
8280 hal_status = RTW_HAL_STATUS_SUCCESS;
8281 } else {
8282 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_start_mcc(): polling timeout\n");
8283 }
8284 exit:
8285 return hal_status;
8286 }
8287
rtw_hal_mac_stop_mcc(struct hal_info_t * hal,u8 group,u8 macid)8288 enum rtw_hal_status rtw_hal_mac_stop_mcc(struct hal_info_t *hal, u8 group,
8289 u8 macid)
8290 {
8291 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8292 struct mac_ax_adapter *mac = hal_to_mac(hal);
8293 u32 mac_status;
8294 u16 loop_cnt = 0;
8295
8296 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_stop_mcc(): group(%d), macid(%d)\n",
8297 group, macid);
8298 if (mac == NULL)
8299 goto exit;
8300 /*prev_groups always set to 1, driver stop all group pattern in the same hw band.*/
8301 mac_status = mac->ops->stop_mcc(mac, group, macid, 1);
8302 if (mac_status != MACSUCCESS) {
8303 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_stop_mcc(): fault, status = %d.\n",
8304 mac_status);
8305 goto exit;
8306 }
8307 do {
8308 if (mac->ops->check_stop_mcc_done(mac, group) ==
8309 MACSUCCESS)
8310 break;
8311 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8312 loop_cnt++;
8313 } while (loop_cnt < POLLING_HALMAC_CNT);
8314
8315 if (loop_cnt < POLLING_HALMAC_CNT) {
8316 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_stop_mcc(): polling ok, count(%d)\n",
8317 loop_cnt);
8318 hal_status = RTW_HAL_STATUS_SUCCESS;
8319 } else {
8320 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_stop_mcc(): polling timeout\n");
8321 }
8322 exit:
8323 return hal_status;
8324 }
8325
rtw_hal_mac_reset_mcc_group(struct hal_info_t * hal,u8 group)8326 enum rtw_hal_status rtw_hal_mac_reset_mcc_group(struct hal_info_t *hal, u8 group)
8327 {
8328 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8329 struct mac_ax_adapter *mac = hal_to_mac(hal);
8330 u32 mac_status;
8331
8332 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> %s(): group(%d)\n",
8333 __func__, group);
8334 if (mac == NULL)
8335 goto exit;
8336
8337 mac_status = mac->ops->reset_mcc_group(mac, group);
8338 if (mac_status != MACSUCCESS) {
8339 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_,
8340 "%s(): reset group(%d) fail, status = %d.\n",
8341 __func__, group, mac_status);
8342 goto exit;
8343 } else {
8344 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_,
8345 "%s(): reset group(%d) ok.\n",
8346 __func__, group);
8347 hal_status = RTW_HAL_STATUS_SUCCESS;
8348 }
8349 exit:
8350 return hal_status;
8351 }
8352
rtw_hal_mac_del_mcc_group(struct hal_info_t * hal,u8 group)8353 enum rtw_hal_status rtw_hal_mac_del_mcc_group(struct hal_info_t *hal, u8 group)
8354 {
8355 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8356 struct mac_ax_adapter *mac = hal_to_mac(hal);
8357 u32 mac_status;
8358 u16 loop_cnt = 0;
8359
8360 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_del_mcc_group(): group(%d)\n",
8361 group);
8362 if (mac == NULL)
8363 goto exit;
8364 /*prev_groups always set to 1, driver stop all group pattern in the same hw band.*/
8365 mac_status = mac->ops->del_mcc_group(mac, group, 1);
8366 if (mac_status != MACSUCCESS) {
8367 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_del_mcc_group(): fault, status = %d.\n",
8368 mac_status);
8369 goto exit;
8370 }
8371
8372 do {
8373 if (mac->ops->check_del_mcc_group_done(mac, group) ==
8374 MACSUCCESS)
8375 break;
8376 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8377 loop_cnt++;
8378 } while (loop_cnt < POLLING_HALMAC_CNT);
8379
8380 if (loop_cnt < POLLING_HALMAC_CNT) {
8381 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_del_mcc_group(): polling ok, count(%d)\n",
8382 loop_cnt);
8383 hal_status = RTW_HAL_STATUS_SUCCESS;
8384 } else {
8385 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_del_mcc_group(): polling timeout\n");
8386 }
8387 exit:
8388 return hal_status;
8389 }
8390
rtw_hal_mac_mcc_request_tsf(struct hal_info_t * hal,u8 group,u8 macid_x,u8 macid_y)8391 enum rtw_hal_status rtw_hal_mac_mcc_request_tsf(struct hal_info_t *hal,
8392 u8 group, u8 macid_x, u8 macid_y)
8393 {
8394 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8395 struct mac_ax_adapter *mac = hal_to_mac(hal);
8396 u32 mac_status;
8397 u16 loop_cnt = 0;
8398
8399 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_mcc_request_tsf(): group(%d), macid_x(%d), macid_y(%d)\n",
8400 group, macid_x, macid_y);
8401 if (mac == NULL)
8402 goto exit;
8403 mac_status = mac->ops->mcc_request_tsf(mac, group, macid_x, macid_y);
8404 if (mac_status != MACSUCCESS) {
8405 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_request_tsf(): fault, status = %d.\n",
8406 mac_status);
8407 goto exit;
8408 }
8409
8410 do {
8411 if (mac->ops->check_mcc_request_tsf_done(mac, group) ==
8412 MACSUCCESS)
8413 break;
8414 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8415 loop_cnt++;
8416 } while (loop_cnt < POLLING_HALMAC_CNT);
8417
8418 if (loop_cnt < POLLING_HALMAC_CNT) {
8419 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_mcc_request_tsf(): polling ok, count(%d)\n",
8420 loop_cnt);
8421 hal_status = RTW_HAL_STATUS_SUCCESS;
8422 } else {
8423 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_request_tsf(): polling timeout\n");
8424 }
8425 exit:
8426 return hal_status;
8427 }
8428
rtw_hal_mac_mcc_macid_bitmap(struct hal_info_t * hal,u8 group,u8 macid,u8 * bitmap,u8 len)8429 enum rtw_hal_status rtw_hal_mac_mcc_macid_bitmap(struct hal_info_t *hal,
8430 u8 group, u8 macid, u8 *bitmap, u8 len)
8431 {
8432 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8433 struct mac_ax_adapter *mac = hal_to_mac(hal);
8434 u32 mac_status;
8435 u16 loop_cnt = 0;
8436
8437 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_mcc_macid_bitmap(): group(%d), macid(%d)\n",
8438 group, macid);
8439 if (mac == NULL)
8440 goto exit;
8441 mac_status = mac->ops->mcc_macid_bitmap(mac, group, macid, bitmap, len);
8442 if (mac_status != MACSUCCESS) {
8443 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_macid_bitmap(): fault, status = %d.\n",
8444 mac_status);
8445 goto exit;
8446 }
8447
8448 do {
8449 if (mac->ops->check_mcc_macid_bitmap_done(mac, group) ==
8450 MACSUCCESS)
8451 break;
8452 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8453 loop_cnt++;
8454 } while (loop_cnt < POLLING_HALMAC_CNT);
8455
8456 if (loop_cnt < POLLING_HALMAC_CNT) {
8457 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_mcc_macid_bitmap(): polling ok, count(%d)\n",
8458 loop_cnt);
8459 hal_status = RTW_HAL_STATUS_SUCCESS;
8460 } else {
8461 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_macid_bitmap(): polling timeout\n");
8462 }
8463 exit:
8464 return hal_status;
8465 }
8466
rtw_hal_mac_mcc_sync_enable(struct hal_info_t * hal,u8 group,u8 source,u8 target,u8 offset)8467 enum rtw_hal_status rtw_hal_mac_mcc_sync_enable(struct hal_info_t *hal,
8468 u8 group, u8 source, u8 target, u8 offset)
8469 {
8470 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8471 struct mac_ax_adapter *mac = hal_to_mac(hal);
8472 u32 mac_status;
8473 u16 loop_cnt = 0;
8474
8475 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_mcc_sync_enable(): group(%d), source macid(%d), target macid(%d), offset(%d)\n",
8476 group, source, target, offset);
8477 if (mac == NULL)
8478 goto exit;
8479 mac_status = mac->ops->mcc_sync_enable(mac, group, source, target, offset);
8480 if (mac_status != MACSUCCESS) {
8481 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "mac_mcc_sync_enable(): fault, status = %d.\n",
8482 mac_status);
8483 goto exit;
8484 }
8485 do {
8486 if (mac->ops->check_mcc_sync_enable_done(mac, group) ==
8487 MACSUCCESS)
8488 break;
8489 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8490 loop_cnt++;
8491 } while (loop_cnt < POLLING_HALMAC_CNT);
8492
8493 if (loop_cnt < POLLING_HALMAC_CNT) {
8494 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "mac_mcc_sync_enable(): polling ok, count(%d)\n",
8495 loop_cnt);
8496 hal_status = RTW_HAL_STATUS_SUCCESS;
8497 } else {
8498 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "mac_mcc_sync_enable(): polling timeout\n");
8499 }
8500 exit:
8501 return hal_status;
8502 }
8503
rtw_hal_mac_set_duration(struct hal_info_t * hal,struct rtw_phl_mcc_en_info * en_info,struct rtw_phl_mcc_bt_info * bt_info)8504 enum rtw_hal_status rtw_hal_mac_set_duration(struct hal_info_t *hal,
8505 struct rtw_phl_mcc_en_info *en_info,
8506 struct rtw_phl_mcc_bt_info *bt_info)
8507 {
8508 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8509 struct mac_ax_adapter *mac = hal_to_mac(hal);
8510 struct mac_ax_mcc_duration_info info = {0};
8511 u32 mac_status;
8512 u16 loop_cnt = 0;
8513
8514 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_set_duration()\n");
8515 _hal_mac_mcc_fill_duration_info(en_info, bt_info, &info);
8516 mac_status = mac->ops->mcc_set_duration(mac, &info);
8517 if (mac_status != MACSUCCESS) {
8518 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_set_duration(): fault, status = %d.\n",
8519 mac_status);
8520 goto exit;
8521 }
8522 do {
8523 if (mac->ops->check_mcc_set_duration_done(mac, (u8)info.group)
8524 == MACSUCCESS)
8525 break;
8526 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8527 loop_cnt++;
8528 } while (loop_cnt < POLLING_HALMAC_CNT);
8529
8530 if (loop_cnt < POLLING_HALMAC_CNT) {
8531 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_set_duration(): polling ok, count(%d)\n",
8532 loop_cnt);
8533 hal_status = RTW_HAL_STATUS_SUCCESS;
8534 } else {
8535 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_set_duration(): polling timeout\n");
8536 }
8537 exit:
8538 return hal_status;
8539
8540 }
8541
rtw_hal_mac_get_mcc_tsf_rpt(struct hal_info_t * hal,u8 group,u32 * tsf_x_h,u32 * tsf_x_l,u32 * tsf_y_h,u32 * tsf_y_l)8542 enum rtw_hal_status rtw_hal_mac_get_mcc_tsf_rpt(struct hal_info_t *hal,
8543 u8 group, u32 *tsf_x_h, u32 *tsf_x_l,
8544 u32 *tsf_y_h, u32 *tsf_y_l)
8545 {
8546 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8547 struct mac_ax_adapter *mac = hal_to_mac(hal);
8548 u32 mac_status;
8549
8550 if (mac == NULL)
8551 goto exit;
8552 mac_status = mac->ops->get_mcc_tsf_rpt(mac, group, tsf_x_h, tsf_x_l,
8553 tsf_y_h, tsf_y_l);
8554 if (mac_status != MACSUCCESS) {
8555 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_get_mcc_tsf_rpt(): fault, status = %d.\n",
8556 mac_status);
8557 goto exit;
8558 }
8559 hal_status = RTW_HAL_STATUS_SUCCESS;
8560 exit:
8561 return hal_status;
8562 }
8563
rtw_hal_mac_get_mcc_status_rpt(struct hal_info_t * hal,u8 group,u8 * status,u32 * tsf_h,u32 * tsf_l)8564 enum rtw_hal_status rtw_hal_mac_get_mcc_status_rpt(struct hal_info_t *hal,
8565 u8 group, u8 *status, u32 *tsf_h, u32 *tsf_l)
8566 {
8567 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8568 struct mac_ax_adapter *mac = hal_to_mac(hal);
8569 u32 mac_status;
8570
8571 if (mac == NULL)
8572 goto exit;
8573 mac_status = mac->ops->get_mcc_status_rpt(mac, group, status, tsf_h,
8574 tsf_l);
8575 if (mac_status != MACSUCCESS) {
8576 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "mac_mcc_sync_enable(): fault, status = %d.\n",
8577 mac_status);
8578 goto exit;
8579 }
8580 hal_status = RTW_HAL_STATUS_SUCCESS;
8581 exit:
8582 return hal_status;
8583 }
8584
rtw_hal_mac_get_mcc_group(struct hal_info_t * hal,u8 * group)8585 enum rtw_hal_status rtw_hal_mac_get_mcc_group(struct hal_info_t *hal, u8 *group)
8586 {
8587 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8588 struct mac_ax_adapter *mac = hal_to_mac(hal);
8589 u32 mac_status;
8590
8591 if (mac == NULL)
8592 goto exit;
8593 mac_status = mac->ops->get_mcc_group(mac, group);
8594 if (mac_status != MACSUCCESS) {
8595 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_get_mcc_group(): fault, status = %d.\n",
8596 mac_status);
8597 goto exit;
8598 }
8599 hal_status = RTW_HAL_STATUS_SUCCESS;
8600 exit:
8601 return hal_status;
8602 }
8603 #endif /* CONFIG_MCC_SUPPORT */
8604
8605 #ifdef CONFIG_PHL_P2PPS
8606 #define P2P_ACT_INIT 0
8607 #define P2P_ACT_UPDATE 1
8608 #define P2P_ACT_REMOVE 2
8609 #define P2P_ACT_TERMINATE 3
8610
8611 #define P2P_TYPE_GO 0
8612 #define P2P_TYPE_GC 1
8613
_hal_mac_dump_p2p_act_struct(struct mac_ax_p2p_act_info * mac_p2p_info)8614 void _hal_mac_dump_p2p_act_struct(struct mac_ax_p2p_act_info *mac_p2p_info)
8615 {
8616 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): macid = %d\n",
8617 mac_p2p_info->macid);
8618 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): noaid = %d\n",
8619 mac_p2p_info->noaid);
8620 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): act = %d\n",
8621 mac_p2p_info->act);
8622 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): type = %d\n",
8623 mac_p2p_info->type);
8624 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): all_slep = %d\n",
8625 mac_p2p_info->all_slep);
8626 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): srt = %x\n",
8627 mac_p2p_info->srt);
8628 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): itvl = %d\n",
8629 mac_p2p_info->itvl);
8630 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): dur = %d\n",
8631 mac_p2p_info->dur);
8632 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): cnt = %d\n",
8633 mac_p2p_info->cnt);
8634 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): ctw = %d\n",
8635 mac_p2p_info->ctw);
8636 }
8637
_hal_mac_noa_fill_info(u8 action,struct rtw_phl_noa_desc * desc,u16 macid,struct mac_ax_p2p_act_info * mac_p2p_info)8638 void _hal_mac_noa_fill_info(u8 action,
8639 struct rtw_phl_noa_desc *desc,
8640 u16 macid,
8641 struct mac_ax_p2p_act_info *mac_p2p_info)
8642 {
8643 struct rtw_wifi_role_t *wrole = desc->w_role;
8644
8645 mac_p2p_info->macid = (u8)macid;
8646 mac_p2p_info->noaid = desc->noa_id;
8647 mac_p2p_info->act = action;
8648 if (wrole->type == PHL_RTYPE_AP)
8649 mac_p2p_info->type = P2P_TYPE_GO;
8650 else if (wrole->type == PHL_RTYPE_STATION)
8651 mac_p2p_info->type = P2P_TYPE_GC;
8652 mac_p2p_info->srt = desc->start_t_l;
8653 mac_p2p_info->itvl = desc->interval;
8654 mac_p2p_info->dur = desc->duration;
8655 mac_p2p_info->cnt = desc->count;
8656 }
8657
_hal_mac_get_p2p_stat(struct hal_info_t * hal)8658 enum rtw_hal_status _hal_mac_get_p2p_stat(struct hal_info_t *hal)
8659 {
8660 struct mac_ax_adapter *mac = hal_to_mac(hal);
8661 u16 loop_cnt;
8662 u32 m_stat;
8663
8664 for (loop_cnt = 0; loop_cnt < POLLING_HALMAC_CNT; loop_cnt++) {
8665 m_stat = mac->ops->get_p2p_stat(mac) ;
8666 if (m_stat == MACSUCCESS) {
8667 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_get_p2p_stat(): polling ok, count(%d)\n",
8668 loop_cnt);
8669 return RTW_HAL_STATUS_SUCCESS;
8670 } else if (m_stat == MACP2PSTFAIL) {
8671 PHL_TRACE(COMP_PHL_P2PPS, _PHL_ERR_, "[NoA]_hal_mac_get_p2p_stat(): polling error, count(%d)\n",
8672 loop_cnt);
8673 return RTW_HAL_STATUS_FAILURE;
8674 }
8675 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8676 }
8677 PHL_TRACE(COMP_PHL_P2PPS, _PHL_ERR_, "[NoA]_hal_mac_get_p2p_stat(): polling timeout!\n");
8678 return RTW_HAL_STATUS_FAILURE;
8679 }
8680
8681
_hal_mac_set_p2p_act(struct hal_info_t * hal,struct mac_ax_p2p_act_info * mac_p2p_info)8682 enum rtw_hal_status _hal_mac_set_p2p_act(struct hal_info_t *hal,
8683 struct mac_ax_p2p_act_info *mac_p2p_info)
8684 {
8685 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8686 struct mac_ax_adapter *mac = hal_to_mac(hal);
8687 u32 m_stat;
8688
8689 m_stat = mac->ops->p2p_act_h2c(mac, mac_p2p_info);
8690 if (m_stat != MACSUCCESS) {
8691 PHL_TRACE(COMP_PHL_P2PPS, _PHL_ERR_, "[NoA]_hal_mac_set_noa_act(): Fault, status = %d, Action = %d\n",
8692 m_stat, mac_p2p_info->act);
8693 return RTW_HAL_STATUS_MAC_API_FAILURE;
8694 }
8695 h_stat = _hal_mac_get_p2p_stat(hal);
8696 return h_stat;
8697 }
8698
rtw_hal_mac_noa_init(struct hal_info_t * hal,struct rtw_phl_noa_info * noa_info,struct rtw_phl_noa_desc * in_desc,u16 macid)8699 enum rtw_hal_status rtw_hal_mac_noa_init(struct hal_info_t *hal,
8700 struct rtw_phl_noa_info *noa_info,
8701 struct rtw_phl_noa_desc *in_desc,
8702 u16 macid)
8703 {
8704 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8705 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8706
8707 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_init()\n");
8708 _hal_mac_noa_fill_info(P2P_ACT_INIT, in_desc, macid, &mac_p2p_info);
8709 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8710 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8711 return h_stat;
8712 }
8713
rtw_hal_mac_noa_update(struct hal_info_t * hal,struct rtw_phl_noa_info * noa_info,struct rtw_phl_noa_desc * in_desc,u16 macid)8714 enum rtw_hal_status rtw_hal_mac_noa_update(struct hal_info_t *hal,
8715 struct rtw_phl_noa_info *noa_info,
8716 struct rtw_phl_noa_desc *in_desc,
8717 u16 macid)
8718 {
8719 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8720 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8721
8722 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_update()\n");
8723 _hal_mac_noa_fill_info(P2P_ACT_UPDATE, in_desc, macid, &mac_p2p_info);
8724 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8725 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8726 return h_stat;
8727 }
8728
rtw_hal_mac_noa_remove(struct hal_info_t * hal,struct rtw_phl_noa_info * noa_info,struct rtw_phl_noa_desc * in_desc,u16 macid)8729 enum rtw_hal_status rtw_hal_mac_noa_remove(struct hal_info_t *hal,
8730 struct rtw_phl_noa_info *noa_info,
8731 struct rtw_phl_noa_desc *in_desc,
8732 u16 macid)
8733 {
8734 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8735 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8736
8737 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_remove()\n");
8738 _hal_mac_noa_fill_info(P2P_ACT_REMOVE, in_desc, macid, &mac_p2p_info);
8739 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8740 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8741 return h_stat;
8742
8743 }
8744
rtw_hal_mac_noa_terminate(struct hal_info_t * hal,struct rtw_phl_noa_info * noa_info,struct rtw_phl_noa_desc * in_desc,u16 macid)8745 enum rtw_hal_status rtw_hal_mac_noa_terminate(struct hal_info_t *hal,
8746 struct rtw_phl_noa_info *noa_info,
8747 struct rtw_phl_noa_desc *in_desc,
8748 u16 macid)
8749 {
8750 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8751 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8752
8753 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_terminate()\n");
8754 _hal_mac_noa_fill_info(P2P_ACT_TERMINATE, in_desc, macid, &mac_p2p_info);
8755 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8756 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8757 return h_stat;
8758
8759 }
8760
rtw_hal_mac_tsf32_tog_enable(struct hal_info_t * hal,u8 hw_band,u8 port,u16 early)8761 enum rtw_hal_status rtw_hal_mac_tsf32_tog_enable(struct hal_info_t *hal,
8762 u8 hw_band,
8763 u8 port,
8764 u16 early)
8765 {
8766 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8767 struct mac_ax_t32_togl_info mac_t32_tog_info = {0};
8768 struct mac_ax_adapter *mac = hal_to_mac(hal);
8769 u32 m_stat;
8770
8771 mac_t32_tog_info.band = hw_band;
8772 mac_t32_tog_info.port = port;
8773 mac_t32_tog_info.en = true;
8774 mac_t32_tog_info.early = early;
8775 m_stat = mac->ops->tsf32_togl_h2c(mac, &mac_t32_tog_info);
8776 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_tsf32_tog_enable() m_stat = %d\n",
8777 m_stat);
8778 if(m_stat == MACSUCCESS)
8779 h_stat = RTW_HAL_STATUS_SUCCESS;
8780 return h_stat;
8781 }
8782
rtw_hal_mac_tsf32_tog_disable(struct hal_info_t * hal,u8 hw_band,u8 port)8783 enum rtw_hal_status rtw_hal_mac_tsf32_tog_disable(struct hal_info_t *hal,
8784 u8 hw_band,
8785 u8 port)
8786 {
8787 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8788 struct mac_ax_t32_togl_info mac_t32_tog_info = {0};
8789 struct mac_ax_adapter *mac = hal_to_mac(hal);
8790 u32 m_stat;
8791
8792 mac_t32_tog_info.band = hw_band;
8793 mac_t32_tog_info.port = port;
8794 mac_t32_tog_info.en = false;
8795 m_stat = mac->ops->tsf32_togl_h2c(mac, &mac_t32_tog_info);
8796 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_tsf32_tog_disable() m_stat = %d\n",
8797 m_stat);
8798 if(m_stat == MACSUCCESS)
8799 h_stat = RTW_HAL_STATUS_SUCCESS;
8800 return h_stat;
8801 }
8802
rtw_hal_mac_get_tsf32_tog_rpt(struct hal_info_t * hal,struct rtw_phl_tsf32_tog_rpt * rpt)8803 enum rtw_hal_status rtw_hal_mac_get_tsf32_tog_rpt(struct hal_info_t *hal,
8804 struct rtw_phl_tsf32_tog_rpt *rpt)
8805 {
8806 struct mac_ax_adapter *mac = hal_to_mac(hal);
8807 struct mac_ax_t32_togl_rpt m_rpt = {0};
8808 u32 m_stat = 0;
8809 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_get_tsf32_tog_rpt()\n");
8810 m_stat = mac->ops->get_t32_togl_rpt(mac, &m_rpt);
8811 if (m_stat != MACSUCCESS) {
8812 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_get_tsf32_tog_rpt() MAC FAIL(%d)!\n",
8813 m_stat);
8814 return RTW_HAL_STATUS_FAILURE;
8815 }
8816 rpt->band = m_rpt.band;
8817 rpt->port = m_rpt.port;
8818 rpt->valid = m_rpt.valid;
8819 rpt->early = m_rpt.early;
8820 rpt->status = m_rpt.status;
8821 rpt->tsf_l = m_rpt.tsf_l;
8822 rpt->tsf_h = m_rpt.tsf_h;
8823 return RTW_HAL_STATUS_SUCCESS;
8824 }
8825 #endif
rtw_hal_mac_notification(struct hal_info_t * hal_info,enum phl_msg_evt_id event,u8 band)8826 void rtw_hal_mac_notification(struct hal_info_t *hal_info,
8827 enum phl_msg_evt_id event,
8828 u8 band)
8829 {
8830 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8831
8832 mac->ops->event_notify(mac, event, band);
8833 }
8834
rtw_hal_mac_cmd_notification(struct hal_info_t * hal_info,void * hal_cmd,u8 band)8835 void rtw_hal_mac_cmd_notification(struct hal_info_t *hal_info,
8836 void *hal_cmd,
8837 u8 band)
8838 {
8839 /*todo*/
8840 }
8841
8842 enum rtw_hal_status
rtw_hal_mac_trigger_fw_conflict(struct hal_info_t * hal_info,u32 addr,u8 vol)8843 rtw_hal_mac_trigger_fw_conflict(struct hal_info_t *hal_info, u32 addr, u8 vol)
8844 {
8845 struct hal_ops_t *hal_ops = hal_get_ops(hal_info);
8846 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8847 u32 i = 0;
8848 u32 convert_mask = 0xffffffff;
8849 u32 val;
8850
8851 /* Switch voltage */
8852 mac->ops->set_hw_value(mac, MAC_AX_HW_SET_CORE_SWR_VOLT, &vol);
8853
8854 /* Trigger method: H2C Halt */
8855 hal_ops->write_macreg(hal_info, 0x168, convert_mask, 0x5dc0007);
8856 hal_ops->write_macreg(hal_info, 0x160, convert_mask, 0x1);
8857
8858 /* loop read reg */
8859 for(i = 0; i<1000; i++){
8860 val = hal_ops->read_macreg(hal_info,
8861 addr,
8862 convert_mask);
8863 PHL_INFO("%s: voltag %d count %d io_value = %x\n", __FUNCTION__,vol, i, val);
8864 }
8865
8866 return RTW_HAL_STATUS_SUCCESS;
8867 }
8868
8869
8870 enum rtw_hal_status
rtw_hal_mac_set_gpio_func(struct rtw_hal_com_t * hal_com,u8 func,s8 gpio_cfg)8871 rtw_hal_mac_set_gpio_func(struct rtw_hal_com_t *hal_com, u8 func, s8 gpio_cfg){
8872 struct hal_info_t *hal_info = hal_com->hal_priv;
8873 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8874 struct mac_ax_ops *ops = mac->ops;
8875 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
8876
8877 ret = ops->set_gpio_func(mac, func, gpio_cfg);
8878
8879 if (ret != MACSUCCESS)
8880 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set GPIO failure, status = %d\n", ret);
8881
8882 return ret;
8883 }
8884
8885 enum rtw_hal_status
rtw_hal_mac_bfee_set_vht_gid(struct hal_info_t * hal,u8 band,struct rtw_phl_gid_pos_tbl * tbl)8886 rtw_hal_mac_bfee_set_vht_gid(struct hal_info_t *hal,
8887 u8 band, struct rtw_phl_gid_pos_tbl *tbl)
8888 {
8889 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
8890 struct mac_gid_pos gid_pos = {0};
8891 struct mac_ax_adapter *mac = hal_to_mac(hal);
8892 u32 mac_status = 0;
8893 u8 i = 0;
8894
8895 gid_pos.band = band;
8896 /* For GID 0~31 */
8897 for (i = 0; i < 4; i++) {
8898 gid_pos.gid_tab[0] |= (tbl->gid_vld[i] << (i << 3));
8899 }
8900
8901 for (i = 0; i < 8; i++) {
8902 if (i < 4)
8903 gid_pos.user_pos[0] |= (tbl->pos[i] << (i << 3));
8904 else
8905 gid_pos.user_pos[1] |= (tbl->pos[i] << ((i - 4) << 3));
8906 }
8907 /* For GID 32~64 */
8908 for (i = 4; i < 8; i++) {
8909 gid_pos.gid_tab[1] |= (tbl->gid_vld[i] << ((i - 4) << 3));
8910 }
8911 for (i = 8; i < 16; i++) {
8912 if (i < 12)
8913 gid_pos.user_pos[2] |= (tbl->pos[i] << ((i - 8) << 3));
8914 else
8915 gid_pos.user_pos[3] |= (tbl->pos[i] << ((i - 12) << 3));
8916 }
8917 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s() : Set VHT GID for band %d;\n",
8918 __func__, band);
8919 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s() : band %d ; gid tbl 0x%x 0x%x;\n",
8920 __func__, band,
8921 gid_pos.gid_tab[0], gid_pos.gid_tab[1]);
8922 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s() : user position 0x%x 0x%x 0x%x 0x%x;\n",
8923 __func__,
8924 gid_pos.user_pos[0], gid_pos.user_pos[1],
8925 gid_pos.user_pos[2], gid_pos.user_pos[3]);
8926
8927 mac_status = mac->ops->gidpos(mac, &gid_pos);
8928 if (mac_status != MACSUCCESS) {
8929 hal_status = RTW_HAL_STATUS_FAILURE;
8930 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
8931 __func__, mac_status);
8932 }
8933
8934 return hal_status;
8935 }
8936
8937 /* acq_val/mgq_val , input unit : us */
8938 enum rtw_hal_status
rtw_hal_mac_set_tx_lifetime(struct hal_info_t * hal,enum phl_band_idx band,bool acq_en,bool mgq_en,u16 acq_val,u16 mgq_val)8939 rtw_hal_mac_set_tx_lifetime(struct hal_info_t *hal, enum phl_band_idx band,
8940 bool acq_en, bool mgq_en, u16 acq_val, u16 mgq_val)
8941 {
8942 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
8943 struct mac_ax_adapter *mac = hal_to_mac(hal);
8944 struct mac_ax_lifetime_cfg cfg = {0};
8945 u32 mac_status = 0;
8946 u16 tmp = 0;
8947 #define HAL_MAC_TX_LIFETIME_UNIT_US_SHT 8 /* 256 us */
8948
8949 if (HW_BAND_1 == band)
8950 cfg.band = 1;
8951 else
8952 cfg.band = 0;
8953
8954 if(true == acq_en) {
8955 cfg.en.acq_en = 1;
8956 tmp = acq_val >> HAL_MAC_TX_LIFETIME_UNIT_US_SHT;
8957 cfg.val.acq_val_1 = tmp;
8958 cfg.val.acq_val_2 = tmp;
8959 cfg.val.acq_val_3 = tmp;
8960 cfg.val.acq_val_4 = tmp;
8961 }
8962
8963 if (true == mgq_en) {
8964 cfg.en.mgq_en = 1;
8965 tmp = mgq_val >> HAL_MAC_TX_LIFETIME_UNIT_US_SHT;
8966 cfg.val.mgq_val = tmp;
8967 }
8968
8969 mac_status = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_LIFETIME_CFG, (void *)&cfg);
8970
8971 if (mac_status != MACSUCCESS) {
8972 hal_status = RTW_HAL_STATUS_FAILURE;
8973 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
8974 __func__, mac_status);
8975 }
8976
8977 return hal_status;
8978 }
8979
8980 #ifdef CONFIG_FW_IO_OFLD_SUPPORT
rtw_hal_mac_add_cmd_ofld(struct rtw_hal_com_t * hal_com,struct rtw_mac_cmd * cmd)8981 enum rtw_hal_status rtw_hal_mac_add_cmd_ofld(struct rtw_hal_com_t *hal_com, struct rtw_mac_cmd *cmd)
8982 {
8983 struct hal_info_t *hal_info = hal_com->hal_priv;
8984 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8985 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8986 u32 mac_status;
8987
8988 if (mac == NULL)
8989 goto exit;
8990 mac_status = mac->ops->add_cmd_ofld(mac, cmd);
8991 if (mac_status != MACSUCCESS) {
8992 PHL_TRACE(COMP_PHL_MAC, _PHL_ERR_, "%s(): fault, status = %d.\n",
8993 __func__, mac_status);
8994 goto exit;
8995 }
8996 hal_status = RTW_HAL_STATUS_SUCCESS;
8997 exit:
8998 return hal_status;
8999 }
9000 #endif
9001
9002
rtw_hal_mac_set_hw_rts_th(struct hal_info_t * hal,u8 band,u16 time_th,u16 len_th)9003 enum rtw_hal_status rtw_hal_mac_set_hw_rts_th(struct hal_info_t *hal, u8 band,
9004 u16 time_th, u16 len_th)
9005 {
9006 struct mac_ax_adapter *mac = hal_to_mac(hal);
9007 struct mac_ax_hw_rts_th hw_rts_th = {0};
9008 u32 mac_err;
9009
9010 PHL_INFO("%s\n", __func__);
9011 _os_mem_set(hal_to_drvpriv(hal), &hw_rts_th, 0, sizeof(hw_rts_th));
9012
9013 hw_rts_th.band = band;
9014 hw_rts_th.time_th = time_th;
9015 hw_rts_th.len_th = len_th;
9016
9017 mac_err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_HW_RTS_TH,
9018 &hw_rts_th);
9019
9020 if (mac_err != MACSUCCESS) {
9021 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
9022 return RTW_HAL_STATUS_FAILURE;
9023 }
9024
9025 return RTW_HAL_STATUS_SUCCESS;
9026 }
9027
rtw_hal_mac_get_efuse_ver_len(struct rtw_hal_com_t * hal_com)9028 u8 rtw_hal_mac_get_efuse_ver_len(struct rtw_hal_com_t *hal_com)
9029 {
9030 struct hal_info_t *hal_info = hal_com->hal_priv;
9031 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9032
9033 return mac->hw_info->efuse_version_size;
9034 }
9035
9036
9037 enum rtw_hal_status
rtw_hal_mac_set_dfs_tb_ctrl(struct hal_info_t * hal_info,u8 set)9038 rtw_hal_mac_set_dfs_tb_ctrl(struct hal_info_t *hal_info, u8 set)
9039 {
9040 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9041 u8 dis_ru_26 = 0;
9042 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
9043
9044 if (set)
9045 dis_ru_26 = 1;
9046 ret = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_TX_RU26_TB, &dis_ru_26);
9047 if (ret != MACSUCCESS) {
9048 PHL_ERR("%s : mac status %d.\n", __func__, ret);
9049 return RTW_HAL_STATUS_FAILURE;
9050 }
9051
9052 return RTW_HAL_STATUS_SUCCESS;
9053 }
9054
9055 enum rtw_hal_status
rtw_hal_mac_patch_rx_rate(struct hal_info_t * hal_info,struct rtw_r_meta_data * mdata)9056 rtw_hal_mac_patch_rx_rate(struct hal_info_t *hal_info, struct rtw_r_meta_data *mdata)
9057 {
9058 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9059 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
9060
9061 ret = mac->ops->patch_rx_rate(mac, mdata);
9062 if (ret != MACSUCCESS) {
9063 PHL_ERR("%s : mac status %d.\n", __func__, ret);
9064 return RTW_HAL_STATUS_FAILURE;
9065 }
9066
9067 return RTW_HAL_STATUS_SUCCESS;
9068 }
9069
9070 /**
9071 * rtw_hal_mac_set_tx_duty() - Set tx pause/un-pause interval
9072 * @hal_info: struct hal_info_t*
9073 * @pause_interval: tx pause interval (ms)
9074 * @tx_interval: tx interval (ms)
9075 *
9076 * Return RTW_HAL_STATUS_SUCCESS when operation success.
9077 */
9078 enum rtw_hal_status
rtw_hal_mac_set_tx_duty(struct hal_info_t * hal_info,u16 pause_interval,u16 tx_interval)9079 rtw_hal_mac_set_tx_duty(struct hal_info_t *hal_info,
9080 u16 pause_interval,
9081 u16 tx_interval)
9082 {
9083 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
9084 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
9085 u32 mac_status = 0;
9086
9087 mac_status = mac->ops->tx_duty(mac, pause_interval, tx_interval);
9088 if (mac_status != MACSUCCESS) {
9089 hal_status = RTW_HAL_STATUS_FAILURE;
9090 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
9091 __func__, mac_status);
9092 }
9093
9094 return hal_status;
9095 }
9096
9097 /**
9098 * rtw_hal_mac_stop_tx_duty() - Stop previous tx duty config
9099 * @hal_info: struct hal_info_t*
9100 *
9101 * Return RTW_HAL_STATUS_SUCCESS when operation success.
9102 */
9103 enum rtw_hal_status
rtw_hal_mac_stop_tx_duty(struct hal_info_t * hal_info)9104 rtw_hal_mac_stop_tx_duty(struct hal_info_t *hal_info)
9105 {
9106 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
9107 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
9108 u32 mac_status = 0;
9109
9110 mac_status = mac->ops->tx_duty_stop(mac);
9111 if (mac_status != MACSUCCESS) {
9112 hal_status = RTW_HAL_STATUS_FAILURE;
9113 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
9114 __func__, mac_status);
9115 }
9116
9117 return hal_status;
9118 }