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 && cfg == NULL)
3055 return RTW_HAL_STATUS_FAILURE;
3056
3057 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3058
3059 if (en) {
3060 info.dev2hst_gpio_en = cfg->dev2hst_gpio_en;
3061 info.disable_inband = cfg->disable_inband;
3062 info.gpio_output_input = cfg->gpio_output_input;
3063 info.gpio_active = cfg->gpio_active;
3064 info.toggle_pulse = cfg->toggle_pulse;
3065 info.data_pin_wakeup = cfg->data_pin_wakeup;
3066 info.gpio_pulse_nonstop = cfg->gpio_pulse_nonstop;
3067 info.gpio_time_unit = cfg->gpio_time_unit;
3068 info.gpio_num = cfg->dev2hst_gpio;
3069 info.gpio_pulse_dura = cfg->gpio_pulse_dura;
3070 info.gpio_pulse_period = cfg->gpio_pulse_period;
3071 info.gpio_pulse_count = cfg->gpio_pulse_count;
3072 info.customer_id = cfg->customer_id;
3073 info.gpio_pulse_en_a = cfg->gpio_pulse_en_a;
3074 info.gpio_duration_unit_a = cfg->gpio_duration_unit_a;
3075 info.gpio_pulse_nonstop_a = cfg->gpio_pulse_nonstop_a;
3076 info.special_reason_a = cfg->special_reason_a;
3077 info.gpio_duration_a = cfg->gpio_duration_a;
3078 info.gpio_pulse_count_a = cfg->gpio_pulse_count_a;
3079 }
3080
3081 if (hal_mac_ops->cfg_dev2hst_gpio(mac, &info))
3082 return RTW_HAL_STATUS_FAILURE;
3083
3084 return RTW_HAL_STATUS_SUCCESS;
3085 }
3086
3087 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)3088 rtw_hal_mac_cfg_wow_wake(struct hal_info_t *hal_info, u16 macid, u8 en, struct rtw_wow_wake_info *cfg)
3089 {
3090 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3091 struct mac_ax_ops *hal_mac_ops = mac->ops;
3092 struct mac_ax_wow_wake_info info = {0};
3093 struct mac_ax_remotectrl_info_parm_ *content = NULL;
3094 struct mac_ax_remotectrl_info_parm_ param;
3095
3096 if (en && cfg == NULL)
3097 return RTW_HAL_STATUS_FAILURE;
3098
3099 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3100
3101 if (en) {
3102 info.wow_en = cfg->wow_en;
3103 info.drop_all_pkt = cfg->drop_all_pkt;
3104 info.rx_parse_after_wake = cfg->rx_parse_after_wake;
3105 info.pairwise_sec_algo = cfg->pairwise_sec_algo;
3106 info.group_sec_algo = cfg->group_sec_algo;
3107 /*
3108 info.bip_sec_algo = cfg->bip_sec_algo;
3109 */
3110 info.pattern_match_en = cfg->pattern_match_en;
3111 info.magic_en = cfg->magic_pkt_en;
3112 info.hw_unicast_en = cfg->hw_unicast_en;
3113 info.fw_unicast_en = cfg->fw_unicast_en;
3114 info.deauth_wakeup = cfg->deauth_wakeup;
3115 info.rekey_wakeup = cfg->rekey_wakeup;
3116 info.eap_wakeup = cfg->eap_wakeup;
3117 info.all_data_wakeup = cfg->all_data_wakeup;
3118
3119 if (cfg->pairwise_sec_algo) {
3120 param.validcheck = cfg->remote_wake_ctrl_info.valid_check;
3121 param.symbolchecken = cfg->remote_wake_ctrl_info.symbol_check_en;
3122 param.lastkeyid = cfg->remote_wake_ctrl_info.gtk_key_idx;
3123 _os_mem_cpy(hal_to_drvpriv(hal_info), param.ptktxiv, cfg->remote_wake_ctrl_info.ptk_tx_iv, IV_LENGTH);
3124 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxptkiv, cfg->remote_wake_ctrl_info.ptk_rx_iv, IV_LENGTH);
3125 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_0, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx0, IV_LENGTH);
3126 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_1, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx1, IV_LENGTH);
3127 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_2, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx2, IV_LENGTH);
3128 _os_mem_cpy(hal_to_drvpriv(hal_info), param.rxgtkiv_3, cfg->remote_wake_ctrl_info.gtk_rx_iv_idx3, IV_LENGTH);
3129 content = ¶m;
3130 }
3131 }
3132
3133 /* should pass cfg->remote_wake_ctrl_info to halmac */
3134 if (hal_mac_ops->cfg_wow_wake(mac, (u8)macid, &info, content))
3135 return RTW_HAL_STATUS_FAILURE;
3136
3137 return RTW_HAL_STATUS_SUCCESS;
3138 }
3139
3140 enum rtw_hal_status
rtw_hal_mac_get_wake_rsn(struct hal_info_t * hal_info,u8 * wake_rsn,u8 * reset)3141 rtw_hal_mac_get_wake_rsn(struct hal_info_t *hal_info, u8 *wake_rsn, u8 *reset)
3142 {
3143 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3144 struct mac_ax_ops *hal_mac_ops = mac->ops;
3145
3146 if (hal_mac_ops->get_wow_wake_rsn(mac, wake_rsn, reset) != MACSUCCESS)
3147 return RTW_HAL_STATUS_FAILURE;
3148
3149 return RTW_HAL_STATUS_SUCCESS;
3150 }
3151
3152 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)3153 rtw_hal_mac_cfg_ndp_ofld(struct hal_info_t *hal_info, u16 macid, u8 en, struct rtw_ndp_ofld_info *cfg)
3154 {
3155 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3156 struct mac_ax_ops *hal_mac_ops = mac->ops;
3157 struct mac_ax_ndp_ofld_info info = {0};
3158 struct mac_ax_ndp_info_parm_ content[2];
3159 void* drv_priv = hal_to_drvpriv(hal_info);
3160 u8 idx = 0;
3161
3162 if (en && cfg == NULL)
3163 return RTW_HAL_STATUS_FAILURE;
3164
3165 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_ndp_ofld_info));
3166 _os_mem_set(drv_priv, content, 0, sizeof(struct mac_ax_ndp_info_parm_)*2);
3167
3168 if (en) {
3169 info.ndp_en = cfg->ndp_en;
3170 info.na_id = cfg->ndp_id;
3171 for (idx = 0; idx < 2; idx++) {
3172 content[idx].enable = cfg->ndp_ofld_content[idx].ndp_en;
3173 _os_mem_cpy(drv_priv,content[idx].targetlinkaddress,
3174 cfg->ndp_ofld_content[idx].mac_addr, MAC_ADDRESS_LENGTH);
3175 content[idx].checkremoveip = cfg->ndp_ofld_content[idx].chk_remote_ip;
3176 _os_mem_cpy(drv_priv,content[idx].remoteipv6address,
3177 cfg->ndp_ofld_content[idx].remote_ipv6_addr, IPV6_ADDRESS_LENGTH);
3178 content[idx].numberoftargetip = cfg->ndp_ofld_content[0].num_target_ip;
3179 _os_mem_cpy(drv_priv,&(content[idx].targetip[0][0]),
3180 &(cfg->ndp_ofld_content[idx].target_ipv6_addr[0][0]), IPV6_ADDRESS_LENGTH*2);
3181 }
3182 }
3183
3184 if (hal_mac_ops->cfg_ndp_ofld(mac, (u8)macid, &info, content))
3185 return RTW_HAL_STATUS_FAILURE;
3186
3187 return RTW_HAL_STATUS_SUCCESS;
3188 }
3189
3190 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)3191 rtw_hal_mac_cfg_arp_ofld(struct hal_info_t *hal_info, u16 macid, u8 en,
3192 struct rtw_arp_ofld_info *cfg)
3193 {
3194
3195 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3196 struct mac_ax_ops *hal_mac_ops = mac->ops;
3197 struct mac_ax_arp_ofld_info info = {0};
3198
3199 if (en && cfg == NULL)
3200 return RTW_HAL_STATUS_FAILURE;
3201
3202 if (en) {
3203 info.arp_en = cfg->arp_en;
3204 info.arp_rsp_id = cfg->arp_rsp_id;
3205 info.arp_action = cfg->arp_action;
3206 }
3207
3208 if (hal_mac_ops->cfg_arp_ofld(mac, (u8)macid, &info, NULL))
3209 return RTW_HAL_STATUS_FAILURE;
3210
3211 return RTW_HAL_STATUS_SUCCESS;
3212 }
3213
3214 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)3215 rtw_hal_mac_cfg_wow_cam(struct hal_info_t *hal_info, u16 macid, u8 en,
3216 struct rtw_pattern_match_info *cfg)
3217 {
3218 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3219 struct mac_ax_ops *hal_mac_ops = mac->ops;
3220 struct rtw_wowcam_upd_info *wowcam_info = NULL;
3221 struct mac_ax_wowcam_upd_info info;
3222 void* drv_priv = hal_to_drvpriv(hal_info);
3223 u8 i = 0;
3224 u8 j = 0;
3225
3226 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s (en: %u) ==>\n", __func__, en);
3227
3228 if (en && cfg == NULL) {
3229 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for input cfg == NULL\n", __func__);
3230 return RTW_HAL_STATUS_FAILURE;
3231 }
3232
3233 /* config each wow cam, no matter valid or not */
3234 for (i = 0; i < MAX_WOW_CAM_NUM; ++i) {
3235 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_wowcam_upd_info));
3236
3237 if (en) {
3238 wowcam_info = &(cfg->wowcam_info[i]);
3239
3240 info.idx = wowcam_info->wow_cam_idx;
3241 info.r_w = wowcam_info->rw;
3242 info.valid = wowcam_info->valid;
3243
3244 if (wowcam_info->valid != 0) {
3245 info.wkfm1 = wowcam_info->wake_mask[0];
3246 info.wkfm2 = wowcam_info->wake_mask[1];
3247 info.wkfm3 = wowcam_info->wake_mask[2];
3248 info.wkfm4 = wowcam_info->wake_mask[3];
3249 info.crc = wowcam_info->match_crc;
3250 info.negative_pattern_match = wowcam_info->is_negative_pattern_match;
3251 info.skip_mac_hdr = wowcam_info->skip_mac_hdr;
3252 info.uc = wowcam_info->uc;
3253 info.mc = wowcam_info->mc;
3254 info.bc = wowcam_info->bc;
3255
3256 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "wow_cam [%u]:\n", info.idx);
3257
3258 for (j = 0; j < 4; ++j)
3259 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- wake_mask[%u] = 0x%08x\n", j, wowcam_info->wake_mask[j]);
3260 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rw, crc = (%u, 0x%08x)\n", info.r_w, info.crc);
3261 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- Neg_ptn_mtch = %u\n", info.negative_pattern_match);
3262 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- SkipMacHdr = %u\n", info.skip_mac_hdr);
3263 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- (UC, MC, BC) = (%u, %u, %u)\n", info.uc, info.mc, info.bc);
3264 } else {
3265 continue;
3266 }
3267 } else {
3268 info.idx = i;
3269 info.r_w = 1;
3270 info.valid = 0;
3271 }
3272
3273 if (hal_mac_ops->cfg_wowcam_upd(mac, &info)) {
3274 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for cfg wowcam(%u)\n", __func__, info.idx);
3275 return RTW_HAL_STATUS_FAILURE;
3276 }
3277 }
3278
3279 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s() <==\n", __func__);
3280
3281 return RTW_HAL_STATUS_SUCCESS;
3282 }
3283
_hal_mac_recv_aoac_report(struct mac_ax_adapter * mac,struct mac_ax_aoac_report * buf,u8 rx_rdy)3284 static u32 _hal_mac_recv_aoac_report(struct mac_ax_adapter *mac, struct mac_ax_aoac_report *buf, u8 rx_rdy)
3285 {
3286 struct mac_ax_ops *hal_mac_ops = mac->ops;
3287 u32 mac_status = 0;
3288
3289 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s(): request aoac report.\n", __func__);
3290
3291 mac_status = hal_mac_ops->request_aoac_report(mac, rx_rdy);
3292
3293 if (mac_status) {
3294 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== mac_status(%u) from request_aoac_report()\n", __func__, mac_status);
3295 return mac_status;
3296 }
3297
3298 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s(): read aoac report\n", __func__);
3299
3300 mac_status = hal_mac_ops->read_aoac_report(mac, buf, rx_rdy);
3301
3302 if (mac_status) {
3303 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== get mac_status(%u) from read_aoac_report()\n", __func__, mac_status);
3304 return mac_status;
3305 }
3306
3307 return mac_status;
3308 }
3309
3310 #define KEY_ID_MASK 0x3
3311 #define KEY_ID_OFFSET 6
3312
_hal_mac_aoac_rpt_chk(struct rtw_aoac_report * aoac_info)3313 enum rtw_hal_status _hal_mac_aoac_rpt_chk(struct rtw_aoac_report *aoac_info)
3314 {
3315 u8 key_id_from_iv = 0;
3316 u32 rx_iv = *((u32 *)aoac_info->ptk_rx_iv);
3317
3318 /* Case I. Aoac report is all zero in phase 0 */
3319 if (rx_iv == 0) {
3320 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): ptk_rx_iv is Zero, treating this case as error.\n", __func__);
3321 return RTW_HAL_STATUS_FAILURE;
3322 }
3323
3324 /* Case II. KEY_IDX does not match with GTK_RX_IV */
3325 key_id_from_iv = (aoac_info->gtk_rx_iv[aoac_info->key_idx][3] >> KEY_ID_OFFSET) & KEY_ID_MASK;
3326
3327 if (key_id_from_iv != aoac_info->key_idx) {
3328 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): Key_idx(%u) not match with the one(%u) parsed from GTK_RX_IV[%u]\n",
3329 __func__, aoac_info->key_idx, key_id_from_iv, aoac_info->key_idx);
3330 return RTW_HAL_STATUS_FAILURE;
3331 }
3332
3333 return RTW_HAL_STATUS_SUCCESS;
3334 }
3335
3336 /*
3337 AOAC_RPT - PHASE 0:
3338 Halmac will get aoac report through c2h reg.
3339
3340 (Cuz at this moment, the rx is still blocked by host.
3341 The rx cannot be resume only if those IV be updated by aoac_rpt)
3342
3343 In PHASE 0, Fw will transfer some necessary info,
3344 such as RX_IV, GTK_KEY_ID, GTK_RX_IV, Rekey_OK and iGTK_ipn.
3345 */
3346
3347 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)3348 _hal_mac_read_aoac_rpt_phase_0(void* drv_priv, struct mac_ax_aoac_report *aoac_rpt_buf, struct rtw_aoac_report *aoac_info)
3349 {
3350 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
3351
3352 aoac_info->rekey_ok = aoac_rpt_buf->rekey_ok;
3353 aoac_info->key_idx = aoac_rpt_buf->key_idx;
3354 _os_mem_cpy(drv_priv, aoac_info->ptk_rx_iv, aoac_rpt_buf->ptk_rx_iv, IV_LENGTH);
3355
3356 switch (aoac_info->key_idx) {
3357 case 0:
3358 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[0], aoac_rpt_buf->gtk_rx_iv_0, IV_LENGTH);
3359 break;
3360 case 1:
3361 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[1], aoac_rpt_buf->gtk_rx_iv_1, IV_LENGTH);
3362 break;
3363 case 2:
3364 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[2], aoac_rpt_buf->gtk_rx_iv_2, IV_LENGTH);
3365 break;
3366 case 3:
3367 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[3], aoac_rpt_buf->gtk_rx_iv_3, IV_LENGTH);
3368 break;
3369 default:
3370 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): Unknown gtk_key_idx(%u)\n", __func__, aoac_info->key_idx);
3371 break;
3372 }
3373
3374 if (aoac_info->rekey_ok)
3375 _os_mem_cpy(drv_priv, aoac_info->igtk_ipn, aoac_rpt_buf->igtk_ipn, sizeof(aoac_rpt_buf->igtk_ipn));
3376
3377 hal_status = _hal_mac_aoac_rpt_chk(aoac_info);
3378
3379 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "PHASE 0:\n");
3380
3381 debug_dump_data((u8 *)aoac_rpt_buf, sizeof(struct mac_ax_aoac_report), "aoac_report");
3382
3383 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rekey_ok = %u\n", aoac_info->rekey_ok);
3384 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- key_idx = %u\n", aoac_info->key_idx);
3385 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)));
3386 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- gtk_rx_iv[%u] = 0x%08x%08x\n",
3387 aoac_info->key_idx,
3388 *((u32*)(aoac_info->gtk_rx_iv[aoac_info->key_idx])+1),
3389 *((u32*)(aoac_info->gtk_rx_iv[aoac_info->key_idx])));
3390
3391 if (aoac_info->rekey_ok)
3392 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- igtk_ipn = 0x%08x%08x\n", *((u32*)(aoac_info->igtk_ipn)+1), *((u32*)(aoac_info->igtk_ipn)));
3393
3394 return hal_status;
3395 }
3396
3397 /*
3398 AOAC_RPT - PHASE 1:
3399 Halmac will get aoac report through c2h pkt.
3400
3401 (Cuz at this moment,
3402 the host has resumed the rx, c2h pkt can be used here.)
3403
3404 In PHASE 1, Fw will transfer all info in aoac report.
3405 Those entries got in phase 0 should remain the same value in phase 1.
3406 */
3407
3408 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)3409 _hal_mac_read_aoac_rpt_phase_1(void* drv_priv, struct mac_ax_aoac_report *aoac_rpt_buf, struct rtw_aoac_report *aoac_info)
3410 {
3411 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
3412 u8 i = 0;
3413
3414 aoac_info->rpt_ver = aoac_rpt_buf->rpt_ver;
3415 aoac_info->sec_type = aoac_rpt_buf->sec_type;
3416 aoac_info->pattern_idx = aoac_rpt_buf->pattern_idx;
3417
3418 _os_mem_cpy(drv_priv, aoac_info->ptk_tx_iv, aoac_rpt_buf->ptk_tx_iv, IV_LENGTH);
3419
3420 for (i = 0; i < 4; ++i) {
3421 switch (i) {
3422 case 0:
3423 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[0], aoac_rpt_buf->gtk_rx_iv_0, IV_LENGTH);
3424 break;
3425 case 1:
3426 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[1], aoac_rpt_buf->gtk_rx_iv_1, IV_LENGTH);
3427 break;
3428 case 2:
3429 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[2], aoac_rpt_buf->gtk_rx_iv_2, IV_LENGTH);
3430 break;
3431 case 3:
3432 _os_mem_cpy(drv_priv, aoac_info->gtk_rx_iv[3], aoac_rpt_buf->gtk_rx_iv_3, IV_LENGTH);
3433 break;
3434 default:
3435 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s(): Unknown gtk_key_idx(%u)\n", __func__, aoac_info->key_idx);
3436 break;
3437 }
3438 }
3439
3440 _os_mem_cpy(drv_priv, aoac_info->gtk, aoac_rpt_buf->gtk, sizeof(aoac_rpt_buf->gtk));
3441 _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));
3442 _os_mem_cpy(drv_priv, aoac_info->igtk_key_id, aoac_rpt_buf->igtk_key_id, sizeof(aoac_rpt_buf->igtk_key_id));
3443 _os_mem_cpy(drv_priv, aoac_info->igtk, aoac_rpt_buf->igtk, sizeof(aoac_rpt_buf->igtk));
3444
3445 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "PHASE 1:\n");
3446
3447 debug_dump_data((u8 *)aoac_rpt_buf, sizeof(struct mac_ax_aoac_report), "aoac_report");
3448
3449 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rekey_ok = %u\n", aoac_info->rekey_ok);
3450 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- key_idx = %u\n", aoac_info->key_idx);
3451 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)));
3452 for(i = 0; i < 4; ++i) {
3453 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- gtk_rx_iv[%u] = 0x%08x%08x\n",
3454 i,
3455 *((u32*)(aoac_info->gtk_rx_iv[i])+1),
3456 *((u32*)(aoac_info->gtk_rx_iv[i])));
3457 }
3458 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)));
3459 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- rpt_ver = %u\n", aoac_info->rpt_ver);
3460 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- sec_type = %u\n", aoac_info->sec_type);
3461 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "- pattern_idx = %u\n", aoac_info->pattern_idx);
3462 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)));
3463 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)));
3464 debug_dump_data(aoac_info->gtk, sizeof(aoac_rpt_buf->gtk), "GTK:");
3465 debug_dump_data(aoac_info->igtk, sizeof(aoac_rpt_buf->igtk), "iGTK:");
3466
3467 return hal_status;
3468 }
3469
3470 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)3471 rtw_hal_mac_get_aoac_rpt(struct hal_info_t *hal_info, struct rtw_aoac_report *aoac_info, u8 rx_ready)
3472 {
3473 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
3474 #ifndef RTW_WKARD_WOW_SKIP_AOAC_RPT
3475 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3476 #endif
3477 struct mac_ax_aoac_report aoac_rpt_buf;
3478 void* drv_priv = hal_to_drvpriv(hal_info);
3479 u32 mac_status = 0;
3480
3481 if (aoac_info == NULL) {
3482 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for input info == NULL\n", __func__);
3483 return RTW_HAL_STATUS_FAILURE;
3484 }
3485
3486 #ifdef RTW_WKARD_WOW_SKIP_AOAC_RPT
3487 mac_status = MACPROCERR;
3488 #else
3489 mac_status = _hal_mac_recv_aoac_report(mac, &aoac_rpt_buf, rx_ready);
3490 #endif
3491
3492 if (mac_status) {
3493 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for _hal_mac_recv_aoac_report fail with mac_status(%u).\n",
3494 __func__, mac_status);
3495 hal_status = RTW_HAL_STATUS_FAILURE;
3496 } else {
3497 if (rx_ready == 0)
3498 hal_status = _hal_mac_read_aoac_rpt_phase_0(drv_priv, &aoac_rpt_buf, aoac_info);
3499 else
3500 hal_status = _hal_mac_read_aoac_rpt_phase_1(drv_priv, &aoac_rpt_buf, aoac_info);
3501 }
3502
3503 return hal_status;
3504 }
3505
3506 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)3507 rtw_hal_mac_cfg_gtk_ofld(struct hal_info_t *hal_info, u16 macid, u8 en,
3508 struct rtw_gtk_ofld_info *cfg)
3509 {
3510 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3511 struct mac_ax_ops *hal_mac_ops = mac->ops;
3512 struct mac_ax_gtk_ofld_info info;
3513 struct mac_ax_gtk_info_parm_ param;
3514 void* drv_priv = hal_to_drvpriv(hal_info);
3515
3516 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_gtk_ofld_info));
3517 _os_mem_set(drv_priv, ¶m, 0, sizeof(struct mac_ax_gtk_info_parm_));
3518
3519 if (en && cfg == NULL) {
3520 PHL_TRACE(COMP_PHL_WOW, _PHL_WARNING_, "%s() <== RTW_HAL_STATUS_FAILURE for input cfg == NULL\n", __func__);
3521 return RTW_HAL_STATUS_FAILURE;
3522 }
3523
3524 if (en) {
3525 info.gtk_en = cfg->gtk_en;
3526 info.tkip_en = cfg->tkip_en;
3527 info.ieee80211w_en = cfg->ieee80211w_en;
3528 info.pairwise_wakeup = cfg->pairwise_wakeup;
3529 info.gtk_rsp_id = cfg->gtk_rsp_id;
3530
3531 info.algo_akm_suit = cfg->akmtype_byte3;
3532
3533 if (info.gtk_en) {
3534 _os_mem_cpy(drv_priv, param.kck, cfg->gtk_ofld_content.kck, cfg->gtk_ofld_content.kck_len);
3535 _os_mem_cpy(drv_priv, param.kek, cfg->gtk_ofld_content.kek, cfg->gtk_ofld_content.kek_len);
3536
3537 if (info.tkip_en)
3538 _os_mem_cpy(drv_priv, param.rxmickey, cfg->gtk_ofld_content.rxmickey, TKIP_MIC_KEY_LENGTH);
3539 }
3540
3541 if (info.ieee80211w_en) {
3542 info.bip_sec_algo = cfg->bip_sec_algo;
3543 info.pmf_sa_query_id = cfg->sa_query_id;
3544
3545 _os_mem_cpy(drv_priv, param.igtk_keyid, cfg->gtk_ofld_content.igtk_keyid, cfg->gtk_ofld_content.igtk_len);
3546 _os_mem_cpy(drv_priv, param.ipn, cfg->gtk_ofld_content.ipn, IGTK_PKT_NUM_LENGTH);
3547 _os_mem_cpy(drv_priv, param.igtk, &(cfg->gtk_ofld_content.igtk[0]), cfg->gtk_ofld_content.igtk_len);
3548
3549 if (cfg->hw_11w_en == 0)
3550 _os_mem_cpy(drv_priv, param.sk, cfg->gtk_ofld_content.psk, cfg->gtk_ofld_content.psk_len);
3551 }
3552 } else {
3553 info.gtk_en = false;
3554 info.ieee80211w_en = false;
3555 }
3556
3557 if (hal_mac_ops->cfg_gtk_ofld(mac, (u8)macid, &info, ¶m))
3558 return RTW_HAL_STATUS_FAILURE;
3559
3560 return RTW_HAL_STATUS_SUCCESS;
3561
3562 }
3563
3564 enum rtw_hal_status
rtw_hal_mac_cfg_realwow(struct hal_info_t * hal_info,u16 macid,u8 en,struct rtw_realwow_info * cfg)3565 rtw_hal_mac_cfg_realwow(struct hal_info_t *hal_info, u16 macid, u8 en,
3566 struct rtw_realwow_info *cfg)
3567 {
3568 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3569 struct mac_ax_ops *hal_mac_ops = mac->ops;
3570 struct mac_ax_realwow_info info = {0};
3571 struct mac_ax_realwowv2_info_parm_ param = {0};
3572 void *drv_priv = hal_to_drvpriv(hal_info);
3573
3574 _os_mem_set(drv_priv, &info, 0, sizeof(struct mac_ax_realwow_info));
3575 _os_mem_set(drv_priv, ¶m, 0, sizeof(struct mac_ax_realwowv2_info_parm_));
3576
3577 if (en) {
3578 info.realwow_en = cfg->realwow_en;
3579 info.auto_wakeup = cfg->auto_wakeup;
3580 info.keepalive_id = cfg->keepalive_id;
3581 info.wakeup_pattern_id = cfg->wakeup_pattern_id;
3582 info.ack_pattern_id = cfg->ack_pattern_id;
3583 if (info.realwow_en) {
3584 param.interval = cfg->realwow_ofld_content.interval;
3585 param.kapktsize = cfg->realwow_ofld_content.keep_alive_pkt_size;
3586 param.acklostlimit = cfg->realwow_ofld_content.ack_lost_limit;
3587 param.ackpatternsize = cfg->realwow_ofld_content.ack_ptrn_size;
3588 param.wakeuppatternsize = cfg->realwow_ofld_content.wakeup_ptrn_size;
3589 param.wakeupsecnum = cfg->realwow_ofld_content.wakeup_sec_num;
3590 }
3591 } else {
3592 info.realwow_en = false;
3593 }
3594
3595 if (hal_mac_ops->cfg_realwow(mac, (u8)macid, &info, ¶m))
3596 return RTW_HAL_STATUS_FAILURE;
3597
3598 return RTW_HAL_STATUS_SUCCESS;
3599 }
3600
rtw_hal_mac_set_wowlan(struct hal_info_t * hal,u8 enter)3601 enum rtw_hal_status rtw_hal_mac_set_wowlan(struct hal_info_t *hal, u8 enter)
3602 {
3603 u32 mac_err = 0;
3604 struct mac_ax_adapter *mac = hal_to_mac(hal);
3605 enum mac_ax_wow_ctrl ctrl = (enter == 1) ? MAC_AX_WOW_ENTER : MAC_AX_WOW_LEAVE;
3606
3607 mac_err = mac->ops->intf_ops->set_wowlan(mac, ctrl);
3608 if (mac_err != MACSUCCESS)
3609 return RTW_HAL_STATUS_FAILURE;
3610
3611 return RTW_HAL_STATUS_SUCCESS;
3612 }
3613
_wow_is_txq_empty(struct mac_ax_tx_queue_empty * val)3614 static bool _wow_is_txq_empty(struct mac_ax_tx_queue_empty *val)
3615 {
3616 u8 i = 0;
3617 u8 size = ARRAY_SIZE(val->macid_txq_empty);
3618
3619 if (!val->others_empty)
3620 return false;
3621
3622 if (!val->band0_mgnt_empty)
3623 return false;
3624
3625 if (!val->band1_mgnt_empty)
3626 return false;
3627
3628 for (i = 0; i < size; i++) {
3629 if (val->macid_txq_empty[i] != 0xFF)
3630 return false;
3631 }
3632
3633 PHL_INFO("%s : others_empty %d.\n", __func__, val->others_empty);
3634 PHL_INFO("%s : band0_mgnt_empty %d.\n", __func__, val->band0_mgnt_empty);
3635 PHL_INFO("%s : band1_mgnt_empty %d.\n", __func__, val->band1_mgnt_empty);
3636 for (i = 0; i < size; i++)
3637 PHL_INFO("%s : macid_txq_empty[%d] %d.\n", __func__, i, val->macid_txq_empty[i]);
3638
3639 return true;
3640 }
3641
3642 #define MAX_WOW_POLLNG_TXQ_EMPTY_TIME 50000 /* us */
3643 #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)3644 enum rtw_hal_status rtw_hal_mac_wow_chk_txq_empty(struct hal_info_t *hal, u8 *empty)
3645 {
3646 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
3647 struct mac_ax_adapter *mac = hal_to_mac(hal);
3648 struct mac_ax_tx_queue_empty val = {0};
3649 u32 start_t = _os_get_cur_time_us();
3650 u8 chk_cnt = 0;
3651
3652 while (1) {
3653
3654 if (phl_get_passing_time_us(start_t) >= MAX_WOW_POLLNG_TXQ_EMPTY_TIME) {
3655 PHL_ERR("%s : reach maximum polling time.\n", __func__);
3656 break;
3657 }
3658
3659 for (chk_cnt = 0; chk_cnt < MAX_WOW_CHK_TXQ_EMPTY_CNT; chk_cnt++) {
3660 if (mac->ops->is_txq_empty(mac, &val) != MACSUCCESS)
3661 break;
3662
3663 if (!_wow_is_txq_empty(&val)) {
3664 break;
3665 } else {
3666 *empty = 1;
3667 }
3668 }
3669
3670 if (*empty)
3671 break;
3672
3673 _os_delay_us(hal_to_drvpriv(hal), 50);
3674 }
3675
3676 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s : polling empty %d with duration %d.\n",
3677 __func__, *empty, phl_get_passing_time_us(start_t));
3678
3679 return hstatus;
3680 }
3681
rtw_hal_mac_wow_wde_drop(struct hal_info_t * hal,u8 band)3682 enum rtw_hal_status rtw_hal_mac_wow_wde_drop(struct hal_info_t *hal, u8 band)
3683 {
3684 struct mac_ax_adapter *mac = hal_to_mac(hal);
3685 struct mac_ax_pkt_drop_info info = {0};
3686 u32 mac_err = 0;
3687
3688 PHL_TRACE(COMP_PHL_WOW, _PHL_INFO_, "%s with band %d.\n", __func__, band);
3689
3690 info.sel = MAC_AX_PKT_DROP_SEL_BAND_ONCE;
3691 info.band = band;
3692
3693 mac_err = mac->ops->pkt_drop(mac, &info);
3694 if (mac_err != MACSUCCESS)
3695 return RTW_HAL_STATUS_FAILURE;
3696
3697 return RTW_HAL_STATUS_SUCCESS;
3698 }
3699
3700 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)3701 rtw_hal_mac_scan_ofld(struct hal_info_t *hal, u16 mac_id, u8 hw_band, u8 hw_port,
3702 struct scan_ofld_info *cfg)
3703 {
3704 struct mac_ax_adapter *mac = hal_to_mac(hal);
3705 struct mac_ax_scanofld_param param = {0};
3706 u32 mac_err = 0;
3707
3708 param.macid = mac_id;
3709 param.port_id = hw_port;
3710 param.band = hw_band;
3711 param.operation = cfg->operation;
3712 param.probe_req_pkt_id = cfg->probe_req_pkt_id;
3713 param.tsf_low = cfg->tsf_low;
3714 param.tsf_high = cfg->tsf_high;
3715 param.scan_type = cfg->mode;
3716 param.norm_pd = cfg->period;
3717 param.norm_cy = cfg->cycle;
3718 param.slow_pd = cfg->slow_period;
3719
3720 if (cfg->tsf_high != 0 || cfg->tsf_low != 0)
3721 param.start_mode = 1;
3722
3723 PHL_INFO("%s : macid/port/band/operation/pkt_id/tsf_low/tsf_high =\
3724 %u/%u/%u/%u/%u/%u/%u \n", __func__,
3725 param.macid, param.port_id, param.band, param.operation,
3726 param.probe_req_pkt_id, param.tsf_low, param.tsf_high);
3727
3728 PHL_INFO("%s : scan_type/norm_pd/norm_cy/slow_pd =\
3729 %u/%u/%u/%u \n", __func__,
3730 param.scan_type, param.norm_pd, param.norm_cy, param.slow_pd);
3731
3732 mac_err = mac->ops->scanofld(mac, ¶m);
3733
3734 if (MACSUCCESS != mac_err) {
3735 PHL_ERR("%s : failed, mac error = %u \n", __func__, mac_err);
3736 return RTW_HAL_STATUS_FAILURE;
3737 }
3738
3739 return RTW_HAL_STATUS_SUCCESS;
3740
3741 }
3742
3743 enum rtw_hal_status
rtw_hal_mac_scan_ofld_chlist_busy(struct hal_info_t * hal)3744 rtw_hal_mac_scan_ofld_chlist_busy(struct hal_info_t *hal)
3745 {
3746 struct mac_ax_adapter *mac = hal_to_mac(hal);
3747
3748 if (mac->ops->scanofld_chlist_busy(mac))
3749 return RTW_HAL_STATUS_FAILURE;
3750
3751 return RTW_HAL_STATUS_SUCCESS;
3752 }
3753
3754 #define MAX_POLLING_FW_STS_TIME 100 /* ms */
3755 enum rtw_hal_status
rtw_hal_mac_scan_ofld_add_ch(struct hal_info_t * hal,struct scan_ofld_ch_info * cfg,bool ofld)3756 rtw_hal_mac_scan_ofld_add_ch(struct hal_info_t *hal,
3757 struct scan_ofld_ch_info *cfg, bool ofld)
3758 {
3759 struct mac_ax_adapter *mac = hal_to_mac(hal);
3760 struct mac_ax_scanofld_chinfo chinfo = {0};
3761 u32 mac_err = 0, poll_cnt = 0, cur_time = _os_get_cur_time_ms();
3762 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
3763 void *drv_priv = hal_to_drvpriv(hal);
3764
3765 chinfo.central_ch = cfg->center_chan;
3766 chinfo.pri_ch = cfg->chan;
3767 chinfo.bw = cfg->bw;
3768 chinfo.period = cfg->period;
3769 chinfo.tx_pkt = cfg->tx_pkt;
3770 chinfo.pause_tx_data = cfg->tx_data_pause;
3771
3772 PHL_INFO("%s : central_ch/pri_ch/bw/period/tx_pkt/pause_tx_data =\
3773 %u/%u/%u/%u/%u/%u \n", __func__,
3774 chinfo.central_ch, chinfo.pri_ch, chinfo.bw, chinfo.period,
3775 chinfo.tx_pkt, chinfo.pause_tx_data);
3776
3777 mac_err = mac->ops->add_scanofld_ch(mac, &chinfo, ofld, true);
3778
3779 if (MACSUCCESS != mac_err) {
3780 PHL_ERR("%s : failed, mac error = %u \n", __func__, mac_err);
3781 return RTW_HAL_STATUS_FAILURE;
3782 }
3783
3784 if (ofld == false)
3785 return RTW_HAL_STATUS_SUCCESS;
3786
3787 /* polling fw status */
3788 while (1) {
3789
3790 if (phl_get_passing_time_ms(cur_time) > MAX_POLLING_FW_STS_TIME) {
3791 PHL_ERR("%s polling fw status timeout !!!\n", __func__);
3792 hstatus = RTW_HAL_STATUS_FAILURE;
3793 break;
3794 }
3795
3796 if (mac->ops->scanofld_chlist_busy(mac)) {
3797 _os_delay_ms(drv_priv, 1);
3798 } else {
3799 PHL_INFO("%s : passing time %ums\n", __func__,
3800 phl_get_passing_time_ms(cur_time));
3801 break;
3802 }
3803
3804 poll_cnt++;
3805 }
3806
3807 return RTW_HAL_STATUS_SUCCESS;
3808 }
3809
3810 enum rtw_hal_status
rtw_hal_mac_scan_ofld_fw_busy(struct hal_info_t * hal)3811 rtw_hal_mac_scan_ofld_fw_busy(struct hal_info_t *hal)
3812 {
3813 struct mac_ax_adapter *mac = hal_to_mac(hal);
3814
3815 if (mac->ops->scanofld_fw_busy(mac))
3816 return RTW_HAL_STATUS_FAILURE;
3817
3818 return RTW_HAL_STATUS_SUCCESS;
3819 }
3820
3821 enum rtw_hal_status
rtw_hal_mac_cfg_nlo(struct hal_info_t * hal,u16 macid,u8 en,struct rtw_nlo_info * cfg)3822 rtw_hal_mac_cfg_nlo(struct hal_info_t *hal, u16 macid, u8 en,
3823 struct rtw_nlo_info *cfg)
3824 {
3825 struct mac_ax_adapter *mac = hal_to_mac(hal);
3826 struct mac_ax_nlo_info info = {0};
3827 struct mac_ax_nlo_networklist_parm_ content = {0};
3828 void *d = hal_to_drvpriv(hal);
3829 u8 i = 0;
3830 u32 mac_err;
3831
3832 info.nlo_en = en;
3833
3834 if (en) {
3835 content.numofentries = cfg->num_of_networks;
3836 _os_mem_cpy(d, content.ssidlen, cfg->ssidlen, content.numofentries);
3837 _os_mem_cpy(d, content.ssid, cfg->ssid,
3838 content.numofentries* MAX_SSID_LEN);
3839 _os_mem_cpy(d, content.chipertype, cfg->chipertype,
3840 content.numofentries);
3841
3842 PHL_INFO("%s : num of ssid %u \n", __func__, content.numofentries);
3843
3844 for (i = 0; i < content.numofentries; i++) {
3845 PHL_INFO("%s : #%u ssid/len = %s/%u \n", __func__, i+1,
3846 (char *)content.ssid[i], content.ssidlen[i]);
3847 }
3848 }
3849
3850 mac_err = mac->ops->cfg_nlo(mac, (u8)macid, &info, &content);
3851
3852 if (MACSUCCESS != mac_err) {
3853 PHL_ERR("%s : failed, mac err (%u) \n", __func__, mac_err);
3854 return RTW_HAL_STATUS_FAILURE;
3855 }
3856
3857 return RTW_HAL_STATUS_SUCCESS;
3858 }
3859
3860 #endif /* CONFIG_WOWLAN */
3861
3862 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)3863 hal_mac_read_efuse(struct mac_ax_adapter *mac, u32 addr, u32 size,
3864 u8 *val, enum mac_ax_efuse_bank bank)
3865 {
3866 if (mac->ops->read_efuse(mac, addr, size, val, bank) != MACSUCCESS)
3867 return RTW_HAL_STATUS_FAILURE;
3868 return RTW_HAL_STATUS_SUCCESS;
3869 }
3870
3871 static enum rtw_hal_status
hal_mac_write_efuse(struct mac_ax_adapter * mac,u32 addr,u8 val,enum mac_ax_efuse_bank bank)3872 hal_mac_write_efuse(struct mac_ax_adapter *mac, u32 addr, u8 val,
3873 enum mac_ax_efuse_bank bank)
3874 {
3875 if (mac->ops->write_efuse(mac, addr, val, bank) != MACSUCCESS)
3876 return RTW_HAL_STATUS_FAILURE;
3877 return RTW_HAL_STATUS_SUCCESS;
3878 }
3879
3880 enum rtw_hal_status
rtw_hal_mac_enable_cpu(struct hal_info_t * hal_info,u8 reason,u8 dlfw)3881 rtw_hal_mac_enable_cpu(struct hal_info_t *hal_info, u8 reason, u8 dlfw)
3882 {
3883 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3884
3885 if (mac->ops->enable_cpu(mac, reason, dlfw) != MACSUCCESS)
3886 return RTW_HAL_STATUS_FAILURE;
3887 return RTW_HAL_STATUS_SUCCESS;
3888 }
3889
3890 enum rtw_hal_status
rtw_hal_mac_disable_cpu(struct hal_info_t * hal_info)3891 rtw_hal_mac_disable_cpu(struct hal_info_t *hal_info)
3892 {
3893 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3894
3895 if (mac->ops->disable_cpu(mac) != MACSUCCESS)
3896 return RTW_HAL_STATUS_FAILURE;
3897 return RTW_HAL_STATUS_SUCCESS;
3898 }
3899
3900 enum rtw_hal_status
rtw_hal_mac_romdl(struct hal_info_t * hal_info,u8 * rom_buf,u32 rom_size)3901 rtw_hal_mac_romdl(struct hal_info_t *hal_info, u8 *rom_buf, u32 rom_size)
3902 {
3903 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3904 u32 rom_addr = 0x18900000;
3905
3906 if (mac->ops->romdl(mac, rom_buf, rom_addr, rom_size) != MACSUCCESS)
3907 return RTW_HAL_STATUS_FAILURE;
3908 return RTW_HAL_STATUS_SUCCESS;
3909 }
3910
3911 enum rtw_hal_status
rtw_hal_mac_fwdl(struct hal_info_t * hal_info,u8 * fw_buf,u32 fw_size)3912 rtw_hal_mac_fwdl(struct hal_info_t *hal_info, u8 *fw_buf, u32 fw_size)
3913 {
3914 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3915 u32 mac_err;
3916
3917 mac_err = mac->ops->fwdl(mac, fw_buf, fw_size);
3918 if (mac_err != MACSUCCESS) {
3919 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
3920 return RTW_HAL_STATUS_FAILURE;
3921 }
3922
3923 hal_mac_print_fw_version(hal_info);
3924
3925 return RTW_HAL_STATUS_SUCCESS;
3926 }
3927
3928 enum rtw_hal_status
rtw_hal_mac_enable_fw(struct hal_info_t * hal_info,u8 fw_type)3929 rtw_hal_mac_enable_fw(struct hal_info_t *hal_info, u8 fw_type)
3930 {
3931 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
3932 u32 mac_err;
3933
3934 mac_err = mac->ops->enable_fw(mac, fw_type);
3935 if (mac_err != MACSUCCESS) {
3936 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
3937 return RTW_HAL_STATUS_FAILURE;
3938 }
3939
3940 hal_mac_print_fw_version(hal_info);
3941 return RTW_HAL_STATUS_SUCCESS;
3942 }
3943
3944 /* */
3945 /**
3946 * rtw_hal_mac_ax_fill_txdesc
3947 * @mac: see struct mac_ax_adapter
3948 * @treq: the xmit request for this tx descriptor
3949 * @wd_buf: the wd buffer to fill
3950 * @wd_len: output, return the total length of filled wd
3951 *
3952 * Note,halmac API for hal and proto type is at hal_api_mac.h
3953 */
3954 enum rtw_hal_status
rtw_hal_mac_ax_fill_txdesc(void * mac,struct rtw_xmit_req * treq,u8 * wd_buf,u32 * wd_len)3955 rtw_hal_mac_ax_fill_txdesc(void *mac, struct rtw_xmit_req *treq,
3956 u8 *wd_buf, u32 *wd_len)
3957 {
3958 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
3959 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
3960
3961 *wd_len = mac_info->ops->txdesc_len(
3962 mac_info,
3963 &treq->mdata);
3964
3965 hal_status = mac_info->ops->build_txdesc(
3966 mac_info,
3967 &treq->mdata, wd_buf, *wd_len);
3968
3969
3970 return hal_status;
3971 }
3972
3973 /**
3974 * rtw_hal_mac_set_hw_ampdu_cfg
3975 * @hal_info: see struct hal_info_t
3976 * @band: target band this AMPDU going to send
3977 * @max_agg_num: AMPDU maximum aggregation number
3978 * @max_agg_time: AMPDU maximum aggregation time, in unit of 32 us
3979 *
3980 * Note,
3981 * (1) halmac API for hal and proto type is at hal_api_mac.h
3982 */
3983 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)3984 rtw_hal_mac_set_hw_ampdu_cfg(struct hal_info_t *hal_info,
3985 u8 band,
3986 u16 max_agg_num, u8 max_agg_time)
3987 {
3988 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
3989 struct mac_ax_ampdu_cfg info;
3990 u32 mac_err;
3991
3992 _os_mem_set(hal_to_drvpriv(hal_info), &info, 0, sizeof(info));
3993
3994 info.band = band;
3995 info.wdbk_mode = MAC_AX_WDBK_MODE_SINGLE_BK;
3996 info.rty_bk_mode = MAC_AX_RTY_BK_MODE_AGG;
3997 info.max_agg_num = max_agg_num;
3998 info.max_agg_time_32us = max_agg_time;
3999
4000 mac_err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_AMPDU_CFG, &info);
4001
4002 if (mac_err != MACSUCCESS)
4003 goto fail;
4004
4005 return RTW_HAL_STATUS_SUCCESS;
4006 fail:
4007 return RTW_HAL_STATUS_MAC_API_FAILURE;
4008 }
4009
4010
4011 /**
4012 * the function to update DMAC control info by halmac api
4013 * @hal_info: see struct hal_info_t
4014 * @dctl_info: structure of dmac control information, define by halmac
4015 * @macid: the macid corresponding to this cmac control info
4016 *
4017 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4018 */
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)4019 enum rtw_hal_status rtw_hal_dmc_tbl_cfg(struct hal_info_t *hal_info,
4020 struct mac_ax_dctl_info *dctl_info,
4021 struct mac_ax_dctl_info *dctl_info_mask,
4022 u16 macid)
4023 {
4024 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4025 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4026 u32 ret = 0;
4027
4028 ret = mac->ops->upd_dctl_info(mac, dctl_info, dctl_info_mask, (u8)macid, 1);
4029
4030 if (0 == ret) {
4031 sts = RTW_HAL_STATUS_SUCCESS;
4032 } else {
4033 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "mac_upd_dctl_info fail (0x%08X)\n",
4034 ret);
4035 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4036 }
4037
4038 return sts;
4039 }
4040
4041
4042
4043 /**
4044 * the function to update CMAC control info by halmac api
4045 * @hal_info: see struct hal_info_t
4046 * @cctl_info: structure of cmac control information, define by halmac
4047 * @macid: the macid corresponding to this cmac control info
4048 *
4049 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4050 */
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)4051 enum rtw_hal_status rtw_hal_cmc_tbl_cfg(struct hal_info_t *hal_info,
4052 struct rtw_hal_mac_ax_cctl_info *cctl_info,
4053 struct rtw_hal_mac_ax_cctl_info *cctl_info_mask,
4054 u16 macid)
4055 {
4056 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4057 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4058 u32 ret = 0;
4059 cctl_info_mask->addr_cam_index = 0;
4060
4061 ret = mac->ops->upd_cctl_info(mac, cctl_info, cctl_info_mask, (u8)macid, 1);
4062
4063 if (0 == ret) {
4064 sts = RTW_HAL_STATUS_SUCCESS;
4065 } else {
4066 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "mac_upd_cctl_info fail (0x%08X)\n",
4067 ret);
4068 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4069 }
4070
4071 return sts;
4072 }
4073
4074
4075 /**
4076 * the function to update BA CAM entry by halmac api
4077 * @hal_info: see struct hal_info_t
4078 * @ba_cam: structure of ba cam entry, define by halmac
4079 *
4080 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4081 */
rtw_hal_bacam_cfg(struct hal_info_t * hal_info,struct mac_ax_bacam_info * ba_cam)4082 enum rtw_hal_status rtw_hal_bacam_cfg(struct hal_info_t *hal_info,
4083 struct mac_ax_bacam_info *ba_cam)
4084 {
4085 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4086 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4087 u32 ret = 0;
4088
4089 ret = mac->ops->bacam_info(mac, ba_cam);
4090
4091 if (0 == ret) {
4092 sts = RTW_HAL_STATUS_SUCCESS;
4093 } else {
4094 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "mac_bacam_info fail (0x%08X)\n",
4095 ret);
4096 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4097 }
4098
4099 return sts;
4100 }
4101
4102 /**
4103 * rtw_hal_mac_set_bw() - Update channel and bandwdith related setting
4104 * @hal_info: struct hal_info_t*
4105 * @band_idx: 0x0: band0, 0x1: band1
4106 * @ch: center channel
4107 * @band: band
4108 * @bw: bandwidth
4109 *
4110 * All channel and bandwidth related MAC setting would be done in
4111 * this function.
4112 * Following setting may be done in this functions:
4113 * a. Enable changing CCK data rate to OFDM 6M function
4114 * to avoid BB/RF abnormal when channel is not 2.4G.
4115 *
4116 * Return RTW_HAL_STATUS_SUCCESS when operation success.
4117 */
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)4118 enum rtw_hal_status rtw_hal_mac_set_bw(struct hal_info_t *hal_info,
4119 u8 band_idx, u8 pri_ch, u8 central_ch_seg0,
4120 u8 central_ch_seg1, enum band_type band,
4121 enum channel_width bw)
4122 {
4123 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4124 struct mac_ax_cfg_bw mac_bw = {0};
4125 u32 ret = 0;
4126
4127 mac_bw.cbw = bw;
4128 mac_bw.band = band_idx;
4129 mac_bw.pri_ch = pri_ch;
4130 mac_bw.central_ch = central_ch_seg0;
4131
4132 ret = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_BW_CFG, &mac_bw);
4133 return (ret == 0) ? (RTW_HAL_STATUS_SUCCESS): (RTW_HAL_STATUS_FAILURE);
4134 }
4135
4136 /**
4137 * rtw_hal_mac_ax_init_bf_role
4138 * @bf_role: 0 = BFEE, 1 = BFER
4139 * @band: 0 = BAND0, 1 = BAND1
4140 */
4141 enum rtw_hal_status
rtw_hal_mac_ax_init_bf_role(struct rtw_hal_com_t * hal_com,u8 bf_role,u8 band)4142 rtw_hal_mac_ax_init_bf_role(struct rtw_hal_com_t *hal_com, u8 bf_role, u8 band)
4143 {
4144 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4145 struct hal_info_t *hal_info = hal_com->hal_priv;
4146 struct mac_ax_adapter *mac_info = hal_to_mac(hal_info);
4147
4148 if (bf_role == HAL_BF_ROLE_BFEE) {
4149 hal_status = mac_info->ops->init_snd_mee(
4150 mac_info, band);
4151 } else {
4152 hal_status = mac_info->ops->init_snd_mer(
4153 mac_info, band);
4154 };
4155 return hal_status;
4156 }
4157
4158
4159 /**
4160 * rtw_hal_mac_ax_disable_bfee
4161 * @band: 0 = BAND0, 1 = BAND1
4162 */
4163 enum rtw_hal_status
rtw_hal_mac_ax_deinit_bfee(struct rtw_hal_com_t * hal_com,u8 band)4164 rtw_hal_mac_ax_deinit_bfee(struct rtw_hal_com_t *hal_com, u8 band)
4165 {
4166 struct hal_info_t *hal_info = hal_com->hal_priv;
4167 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4168 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4169
4170 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4171 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "--> %s : Warning BFee is going to deinit\n", __func__);
4172
4173 hal_status = mac_info->ops->deinit_mee(mac_info, band);
4174
4175 return hal_status;
4176 }
4177
4178
4179 /**
4180 * rtw_hal_mac_ax_bfee_para_reg
4181 * Set BFee capability with STA info by method : Control Register
4182 * input:
4183 * @sta: (struct rtw_phl_stainfo_t *)
4184 */
4185 enum rtw_hal_status
rtw_hal_mac_ax_bfee_para_reg(void * mac,struct rtw_phl_stainfo_t * sta)4186 rtw_hal_mac_ax_bfee_para_reg(void *mac, struct rtw_phl_stainfo_t *sta)
4187 {
4188 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4189 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4190 struct rtw_hal_com_t *hal_com = (struct rtw_hal_com_t *)mac_info->drv_adapter;
4191 struct mac_reg_csi_para csi_para;
4192
4193 _os_mem_set(hal_com->drv_priv, &csi_para, 0, sizeof(csi_para));
4194
4195 csi_para.band = sta->wrole->hw_band;
4196 csi_para.portsel = (sta->wrole->hw_port == 0) ? 0 : 1;
4197 csi_para.nc = (sta->wrole->proto_role_cap.max_nc > sta->asoc_cap.num_snd_dim) ?
4198 sta->asoc_cap.num_snd_dim :
4199 sta->wrole->proto_role_cap.max_nc;
4200 csi_para.nr = (sta->wrole->proto_role_cap.bfme_sts >
4201 sta->asoc_cap.num_snd_dim) ?
4202 sta->asoc_cap.num_snd_dim :
4203 sta->wrole->proto_role_cap.bfme_sts;
4204 /**
4205 * For HE/VHT, Ng = 0 can provide the most detail information.
4206 * Ng do not care bfer cap.
4207 **/
4208 csi_para.ng = 0;
4209 /**
4210 * for HE/VHT, Cb = 1 {6,4}/{9,7} can provide the most detail information
4211 * Cb do not care bfer cap, only care bfee self capabiltiy.
4212 **/
4213 if (sta->wmode & WLAN_MD_11AX)
4214 csi_para.cb = sta->wrole->proto_role_cap.cb_sz_su_fb;
4215 else if (sta->wmode & WLAN_MD_11AC)
4216 csi_para.cb = sta->wrole->proto_role_cap.ht_vht_cb;
4217 else
4218 csi_para.cb = 0;
4219
4220 csi_para.cs = 1; /* Carrier Sense */
4221 if (sta->asoc_cap.ht_ldpc &&
4222 sta->asoc_cap.vht_ldpc &&
4223 sta->asoc_cap.he_ldpc)
4224 csi_para.ldpc_en = 1;
4225
4226 if (sta->asoc_cap.stbc_ht_rx &&
4227 sta->asoc_cap.stbc_vht_rx &&
4228 sta->asoc_cap.stbc_he_rx)
4229 csi_para.stbc_en = 1;
4230
4231 csi_para.bf_en = 0;
4232
4233 hal_status = mac_info->ops->set_csi_para_reg(mac_info, &csi_para);
4234
4235 return hal_status;
4236 }
4237
4238 /**
4239 * rtw_hal_mac_ax_bfee_para_cctl
4240 * Set BFee capability with STA info by method : CMAC Control Table
4241 * input:
4242 * @sta: (struct rtw_phl_stainfo_t *)
4243 */
4244 enum rtw_hal_status
rtw_hal_mac_ax_bfee_para_cctl(void * mac,struct rtw_phl_stainfo_t * sta)4245 rtw_hal_mac_ax_bfee_para_cctl(void *mac, struct rtw_phl_stainfo_t *sta)
4246 {
4247 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4248 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4249 struct rtw_hal_com_t *hal_com =
4250 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4251 struct mac_cctl_csi_para csi_para;
4252
4253 _os_mem_set(hal_com->drv_priv, &csi_para, 0, sizeof(csi_para));
4254
4255 csi_para.macid = (u8)sta->macid;
4256 csi_para.band = sta->wrole->hw_band;
4257 csi_para.nc = (sta->wrole->proto_role_cap.max_nc > sta->asoc_cap.num_snd_dim) ?
4258 sta->asoc_cap.num_snd_dim :
4259 sta->wrole->proto_role_cap.max_nc;
4260 csi_para.nr = (sta->wrole->proto_role_cap.bfme_sts >
4261 sta->asoc_cap.num_snd_dim) ?
4262 sta->asoc_cap.num_snd_dim :
4263 sta->wrole->proto_role_cap.bfme_sts;
4264 /**
4265 * For HE/VHT, Ng = 0 can provide the most detail information.
4266 * Ng do not care bfer cap.
4267 **/
4268 csi_para.ng = 0;
4269 /**
4270 * for HE/VHT, Cb = 1 {6,4}/{9,7} can provide the most detail information
4271 * Cb do not care bfer cap.
4272 **/
4273 if (sta->wmode & WLAN_MD_11AX)
4274 csi_para.cb = sta->wrole->proto_role_cap.cb_sz_su_fb;
4275 else if (sta->wmode & WLAN_MD_11AC)
4276 csi_para.cb = sta->wrole->proto_role_cap.ht_vht_cb;
4277 else
4278 csi_para.cb = 0;
4279 csi_para.cs = 1;
4280 csi_para.bf_en = 0;
4281
4282 if (sta->asoc_cap.stbc_ht_rx &&
4283 sta->asoc_cap.stbc_vht_rx &&
4284 sta->asoc_cap.stbc_he_rx)
4285 csi_para.stbc_en = 1;
4286
4287 if (sta->asoc_cap.ht_ldpc &&
4288 sta->asoc_cap.vht_ldpc &&
4289 sta->asoc_cap.he_ldpc)
4290 csi_para.ldpc_en = 1;
4291 csi_para.rate = MAC_AX_OFDM54;
4292 csi_para.gi_ltf = MAC_AX_SGI_4XHE08;
4293 csi_para.gid_sel = 1;
4294 csi_para.bw = MAC_AX_BW_20M;
4295
4296 hal_status = mac_info->ops->set_csi_para_cctl(mac_info, &csi_para);
4297 return hal_status;
4298 }
4299
4300 enum rtw_hal_status
rtw_hal_mac_ax_bfee_set_csi_rrsc(void * mac,u8 band,u32 rrsc)4301 rtw_hal_mac_ax_bfee_set_csi_rrsc(void *mac, u8 band, u32 rrsc)
4302 {
4303 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4304
4305 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4306
4307 hal_status = mac_info->ops->csi_rrsc(mac_info, band, rrsc);
4308
4309 return hal_status;
4310 }
4311
4312 /**
4313 * rtw_hal_mac_ax_bfee_forced_csi_rate
4314 * set bf report frame rate
4315 * @mac:(struct mac_ax_adapter *)
4316 * @ht_rate:
4317 * @vht_rate:
4318 * @he_rate:
4319 */
4320
4321 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)4322 rtw_hal_mac_ax_bfee_forced_csi_rate(void *mac, struct rtw_phl_stainfo_t *sta,
4323 u8 ht_rate, u8 vht_rate, u8 he_rate)
4324 {
4325 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4326 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4327
4328 hal_status = mac_info->ops->csi_force_rate(mac_info,
4329 sta->wrole->hw_band, ht_rate, vht_rate, he_rate);
4330
4331 return hal_status;
4332 }
4333
4334 /**
4335 * rtw_hal_mac_ax_set_bf_entry
4336 * set HW BF entry for sounding and TxBF
4337 * input :
4338 * @band: BF Entry is band0 or band1;
4339 * @macid: BF Entry's macid
4340 * @bfee_idx: SU/MU HW Entry Index
4341 * @txbf_idx: Tx BF CSI Entry Index
4342 * @buffer_idx: CSI Buffer idx used by TxBF entry
4343 */
4344 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)4345 rtw_hal_mac_ax_set_bf_entry(void *mac, u8 band,
4346 u8 macid, u8 bfee_idx, u16 txbf_idx, u16 buffer_idx)
4347 {
4348 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4349 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4350 /* 1. CSI Buffer Idx */
4351 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",
4352 band, macid, txbf_idx, buffer_idx);
4353 hal_status = mac_info->ops->set_csi_buffer_index(mac_info, band, macid,
4354 txbf_idx, buffer_idx);
4355
4356
4357 /*TODO: this api might revised in the future */
4358 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "set_snd_sts_index: band 0x%x macid 0x%x bf_idx 0x%x\n",
4359 band, macid, bfee_idx);
4360 hal_status = mac_info->ops->set_snd_sts_index(
4361 mac_info, band, macid, bfee_idx);
4362
4363
4364 return hal_status;
4365 }
4366
4367
4368 /**
4369 * rtw_hal_mac_ax_get_snd_sts
4370 * Get HW BF entry sounding status
4371 * input :
4372 * @band: BF Entry is band0 or band1;
4373 * @bfee_idx: SU/MU HW Entry Index
4374 * return
4375 * @hal_status: enum rtw_hal_status
4376 * RTW_HAL_STATUS_SUCCESS = Sounding Success
4377 * RTW_HAL_STATUS_FAILURE = Sounding Fail
4378 */
4379 enum rtw_hal_status
rtw_hal_mac_ax_get_snd_sts(void * mac,u8 band,u8 bfee_idx)4380 rtw_hal_mac_ax_get_snd_sts(void *mac, u8 band, u8 bfee_idx)
4381 {
4382 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4383 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4384 u32 sts = 0;
4385
4386 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "get_snd_sts_index: band 0x%x bf_idx 0x%x\n", band, bfee_idx);
4387 /*TODO: This API shall modify to return sounding status instead of CR value*/
4388 /*MAC Define : #define B_AX_MER_SU_BFMEE0_SND_STS BIT(9)*/
4389 sts = mac_info->ops->get_snd_sts_index(mac_info, band, bfee_idx);
4390 if (sts & B_AX_MER_SU_BFMEE0_SND_STS)
4391 hal_status = RTW_HAL_STATUS_SUCCESS;
4392
4393 return hal_status;
4394 }
4395
4396 /**
4397 * rtw_hal_mac_ax_hw_snd_control
4398 * @band: 0 = BAND0, 1 = BAND1
4399 * @hw_snd_ctrl: 0 = HW_SND_PAUSE 1 = HW_SND_RELEASE
4400 */
4401 enum rtw_hal_status
rtw_hal_mac_ax_hw_snd_control(void * mac,u8 band,u8 hw_snd_ctrl)4402 rtw_hal_mac_ax_hw_snd_control(
4403 void *mac,
4404 u8 band,
4405 u8 hw_snd_ctrl)
4406 {
4407 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4408 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4409 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_,
4410 "mac_hw_snd_pause_release: band 0x%x hw_snd_ctrl 0x%x\n",
4411 band, hw_snd_ctrl);
4412
4413 hal_status = mac_info->ops->hw_snd_pause_release(
4414 mac_info,
4415 band,
4416 hw_snd_ctrl);
4417
4418 return hal_status;
4419 }
4420
4421 /* Tx Frame Exchange Related : MU */
4422 /**
4423 * rtw_hal_mac_ax_mu_sta_upd
4424 * @mac: (struct mac_ax_adapter *)
4425 * @macid: sta macid for configuration
4426 * @bfmu_idx: 0~5, MU STA Index
4427 * @prot_type: RTS/CTS type for the group : enum rtw_hal_protection_type
4428 * @resp_type: Ack Policy for the group : enum rtw_hal_ack_resp_type
4429 * @grp_bitmap: group bitmap for STA,
4430 **/
4431 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)4432 rtw_hal_mac_ax_mu_sta_upd(void *mac, u8 macid, u8 bfmu_idx,
4433 enum rtw_hal_protection_type prot_type,
4434 enum rtw_hal_ack_resp_type resp_type, u8 mugrp_bm)
4435 {
4436 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4437 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4438 struct rtw_hal_com_t *hal_com =
4439 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4440 struct mac_ax_mu_sta_upd sta_info;
4441 u8 i = 0;
4442
4443 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "==> rtw_hal_mac_ax_mu_sta_upd \n");
4444 _os_mem_set(hal_com->drv_priv, &sta_info, 0, sizeof(sta_info));
4445
4446 sta_info.macid = macid;
4447 sta_info.mu_idx = bfmu_idx;
4448 for (i = 0; i < 5; i++) {
4449 if (mugrp_bm & BIT(i)) {
4450 sta_info.prot_rsp_type[i].u.feld_type.protect =
4451 prot_type & 0xF;
4452 sta_info.prot_rsp_type[i].u.feld_type.rsp =
4453 resp_type & 0xF;
4454 } else {
4455 sta_info.prot_rsp_type[i].u.feld_type.protect = 0;
4456 sta_info.prot_rsp_type[i].u.feld_type.rsp = 0;
4457 }
4458 }
4459 sta_info.mugrp_bitmap = mugrp_bm & 0x1F;
4460
4461 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "sta_info.macid = 0x%x \n", sta_info.macid);
4462 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "sta_info.mu_idx = 0x%x \n", sta_info.mu_idx);
4463 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "sta_info.mugrp_bitmap = 0x%x \n", sta_info.mugrp_bitmap);
4464
4465 hal_status = mac_info->ops->mu_sta_upd(mac_info, &sta_info);
4466 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "<== rtw_hal_mac_ax_mu_sta_upd \n");
4467 return hal_status;
4468 }
4469
4470 /**
4471 * rtw_hal_mac_ax_mu_decision_para
4472 * @mac: (struct mac_ax_adapter *)
4473 * @mu_thold: MU MIMO pkt Threshold
4474 * @bypass_thold: by pass mu_thold
4475 * @bypass_tp: by pass MU TP > SU TP check.
4476 **/
4477 enum rtw_hal_status
rtw_hal_mac_ax_mu_decision_para(void * mac,u32 mu_thold,bool bypass_thold,bool bypass_tp)4478 rtw_hal_mac_ax_mu_decision_para(void *mac, u32 mu_thold,
4479 bool bypass_thold, bool bypass_tp)
4480 {
4481 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4482 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4483 struct rtw_hal_com_t *hal_com =
4484 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4485 struct mac_ax_mudecision_para mu_d_para;
4486
4487 _os_mem_set(hal_com->drv_priv, &mu_d_para, 0, sizeof(mu_d_para));
4488
4489 mu_d_para.mu_thold = mu_thold;
4490 mu_d_para.bypass_thold = bypass_thold ? 1 : 0;
4491 mu_d_para.bypass_tp = bypass_tp ? 1 : 0;
4492
4493 hal_status = mac_info->ops->upd_mudecision_para(mac_info, &mu_d_para);
4494
4495 return hal_status;
4496 }
4497
4498 /**
4499 * rtw_hal_mac_ax_set_mu_fix_mode
4500 * @mac: (struct mac_ax_adapter *)
4501 * @gid: GID for STA X + STAY
4502 * @prot_type: RTS/CTS type for the group : enum rtw_hal_protection_type
4503 * @resp_type: Ack Policy for the group : enum rtw_hal_ack_resp_type
4504 * @fix_mu: true = Fix FW decision = MU
4505 * @he: true = Fix TX HE MU, false = Fix TX VHT MU;
4506 * @fix_resp: fix frame exchange ack policy
4507 * @fix_prot: fix frame exchange protection type
4508 **/
4509 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)4510 rtw_hal_mac_ax_set_mu_fix_mode(
4511 void *mac, u8 gid, enum rtw_hal_protection_type prot_type,
4512 enum rtw_hal_ack_resp_type resp_type,
4513 bool fix_mu, bool he, bool fix_resp, bool fix_prot)
4514 {
4515 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4516 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4517 struct rtw_hal_com_t *hal_com =
4518 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4519 struct mac_ax_fixmode_para fix_info;
4520 PHL_INFO("===>rtw_hal_mac_ax_set_mu_fix_mode\n");
4521
4522 _os_mem_set(hal_com->drv_priv, &fix_info, 0, sizeof(fix_info));
4523
4524 fix_info.force_sumuru_en = fix_mu ? 1:0 ;
4525 fix_info.forcemu = fix_mu ? 1:0 ;
4526
4527 if (fix_mu) {
4528 if (!he){
4529 fix_info.fix_fe_vhtmu_en = fix_prot ? 1 : 0;
4530 fix_info.fix_frame_seq_vhtmu = fix_resp ? 1 : 0;
4531 fix_info.prot_type_vhtmu = fix_prot ? prot_type : 5;/*default hw setting*/
4532 fix_info.resp_type_vhtmu = fix_resp ? resp_type : 4;/*default hw setting*/
4533 PHL_INFO("fix_info.prot_type_vhtmu = 0x%x\n", fix_info.prot_type_vhtmu);
4534 PHL_INFO("fix_info.resp_type_vhtmu = 0x%x\n", fix_info.resp_type_vhtmu);
4535
4536 } else {
4537 fix_info.fix_fe_hemu_en = fix_prot ? 1 : 0;;
4538 fix_info.fix_frame_seq_hemu = fix_resp ? 1 : 0;
4539 fix_info.prot_type_hemu = fix_prot ? prot_type : 5;/*default hw setting*/
4540 fix_info.resp_type_hemu = fix_resp ? resp_type : 4;/*default hw setting*/
4541 PHL_INFO("fix_info.prot_type_hemu = 0x%x\n", fix_info.prot_type_hemu);
4542 PHL_INFO("fix_info.resp_type_hemu = 0x%x\n", fix_info.resp_type_hemu);
4543 }
4544
4545 fix_info.mugrpid = gid;
4546 PHL_INFO("fix_info.mugrpid = 0x%x\n", fix_info.mugrpid);
4547 }
4548
4549 hal_status = mac_info->ops->set_fw_fixmode(mac_info, &fix_info);
4550 PHL_INFO("<===rtw_hal_mac_ax_set_mu_fix_mode\n");
4551 return hal_status;
4552 }
4553
4554
4555 void
_hal_mac_fill_mu_sc_tbl_row(u32 * mac_score,void * hal_score)4556 _hal_mac_fill_mu_sc_tbl_row(u32 *mac_score, void *hal_score)
4557 {
4558 struct hal_mu_score_tbl_score *h_score =
4559 (struct hal_mu_score_tbl_score *)hal_score;
4560
4561 *mac_score = (u32)h_score->score[0] |
4562 ((u32)h_score->score[1] << 8) | ((u32)h_score->valid << 10) |
4563 ((u32)h_score->macid << 11);
4564
4565 }
4566 /**
4567 * rtw_hal_mac_ax_set_mu_table_whole
4568 * @mac: (struct mac_ax_adapter *)
4569 *@hal_score_tbl: struct hal_mu_score_tbl *
4570 */
4571 enum rtw_hal_status
rtw_hal_mac_ax_set_mu_table_whole(void * mac,void * hal_score_tbl)4572 rtw_hal_mac_ax_set_mu_table_whole(void *mac, void *hal_score_tbl)
4573 {
4574 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4575 struct mac_ax_adapter *mac_info = (struct mac_ax_adapter *)mac;
4576 struct rtw_hal_com_t *hal_com =
4577 (struct rtw_hal_com_t *)mac_info->drv_adapter;
4578 struct mac_mu_table mu_table;
4579 struct hal_mu_score_tbl *score_tbl = (struct hal_mu_score_tbl *)hal_score_tbl;
4580 _os_mem_set(hal_com->drv_priv, &mu_table, 0, sizeof(mu_table));
4581
4582 /*TODO: halmac api shall refine!!!*/
4583 mu_table.mu_score_tbl_ctrl = (score_tbl->mu_ctrl.mu_sc_thr) |
4584 (score_tbl->mu_ctrl.mu_opt << 2);
4585
4586 /*TODO: if next IC has more than 6 MU STAs!!! */
4587 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_0, &score_tbl->mu_score[0]);
4588 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_1, &score_tbl->mu_score[1]);
4589 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_2, &score_tbl->mu_score[2]);
4590 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_3, &score_tbl->mu_score[3]);
4591 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_4, &score_tbl->mu_score[4]);
4592 _hal_mac_fill_mu_sc_tbl_row(&mu_table.mu_score_tbl_5, &score_tbl->mu_score[5]);
4593
4594 hal_status = mac_info->ops->set_mu_table(mac_info, &mu_table);
4595
4596 return hal_status;
4597 }
4598
4599
4600 enum rtw_hal_status
rtw_hal_mac_parse_c2h(void * hal,u8 * buf,u32 buf_len,void * c2h)4601 rtw_hal_mac_parse_c2h(void *hal, u8 *buf, u32 buf_len, void *c2h)
4602 {
4603 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
4604 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
4605 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4606
4607 hal_status = mac->ops->process_c2h(mac, buf, buf_len, (u8 *)c2h);
4608
4609 return hal_status;
4610 }
4611
4612 /**
4613 * Required information in (hal_handle_rx_buffer_XXXXX case RX_DESC_PKT_TYPE_PPDU_STATUS),
4614 * it cannot be used by core/phl/other hal module
4615 **/
4616 void
_hal_mac_ax_ppdu_sts_to_hal_ppdu_sts(struct mac_ax_ppdu_rpt * mac_ppdu,void * hal_ppdu_sts)4617 _hal_mac_ax_ppdu_sts_to_hal_ppdu_sts(
4618 struct mac_ax_ppdu_rpt *mac_ppdu, void *hal_ppdu_sts)
4619 {
4620 struct hal_ppdu_sts *hal_ppdu =
4621 (struct hal_ppdu_sts *)hal_ppdu_sts;
4622 u8 i = 0;
4623 u32 j = 0;
4624
4625 hal_ppdu->rx_cnt_ptr = mac_ppdu->rx_cnt_ptr;
4626 hal_ppdu->phy_st_ptr = mac_ppdu->phy_st_ptr;
4627 hal_ppdu->plcp_ptr = mac_ppdu->plcp_ptr;
4628 hal_ppdu->plcp_size = mac_ppdu->plcp_size;
4629 hal_ppdu->phy_st_size = mac_ppdu->phy_st_size;
4630 hal_ppdu->rx_cnt_size = mac_ppdu->rx_cnt_size;
4631 hal_ppdu->usr_num = mac_ppdu->usr_num;
4632 for(i = 0; i < mac_ppdu->usr_num; i++) {
4633 if(1 == mac_ppdu->usr[i].vld) {
4634 hal_ppdu->usr[i].vld = 1;
4635 hal_ppdu->usr[i].macid = mac_ppdu->usr[i].macid;
4636 hal_ppdu->usr[i].has_data = mac_ppdu->usr[i].has_data;
4637 hal_ppdu->usr[i].has_ctrl = mac_ppdu->usr[i].has_ctrl;
4638 hal_ppdu->usr[i].has_mgnt = mac_ppdu->usr[i].has_mgnt;
4639 hal_ppdu->usr[i].has_bcn = mac_ppdu->usr[i].has_bcn;
4640 }
4641 }
4642 /* process / decode rx cnt report */
4643 /* TODO: Halmac api shall provid decoder */
4644 if ((0 != hal_ppdu->rx_cnt_size) && (NULL != hal_ppdu->rx_cnt_ptr)) {
4645 for(j = 0; (j < (hal_ppdu->rx_cnt_size/2)) &&
4646 (j < HAL_RXCNT_MAX); j++) {
4647 hal_ppdu->rx_cnt.ppdu_cnt[j] =
4648 ((u16)*(hal_ppdu->rx_cnt_ptr + 2 * j));
4649 }
4650 }
4651 }
4652
4653 /**
4654 * if any information is required for other core/phl module,
4655 * copy to rx meta data or hal_info from halmac ax ppdu status.
4656 **/
4657 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)4658 _hal_mac_ax_ppdu_sts_to_hal_info(struct hal_info_t *hal_info,
4659 struct mac_ax_ppdu_rpt *mac_ppdu, void *rx_mdata)
4660 {
4661 /* struct rtw_r_meta_data *mdata =
4662 (struct rtw_r_meta_data *)rx_mdata; */
4663 return;
4664 }
4665 /**
4666 * rtw_hal_mac_ax_parse_ppdu_sts
4667 * @hal:(struct hal_info_t *)
4668 * @mac_valid:if mac information invalid (from rx desc)
4669 * @buf: pointer of ppdu status, point to header of mac_info
4670 * @buf_l:ppdu status payload size
4671 * @ppdu_sts: (struct hal_ppdu_sts *) for return value to hal
4672 * @rx_mdata: (struct rtw_r_meta_data *) for saving ppdu status
4673 */
4674 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)4675 rtw_hal_mac_ax_parse_ppdu_sts(void *hal, u8 mac_valid, u8 *buf, u16 buf_l,
4676 void *ppdu_sts, void *rx_mdata)
4677 {
4678 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
4679 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
4680 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4681 struct mac_ax_ppdu_rpt ppdu_rpt = {0};
4682
4683 PHL_DBG("%s\n", __FUNCTION__);
4684
4685 hal_status = mac->ops->parse_ppdu(hal_info->mac, buf, buf_l,
4686 mac_valid, &ppdu_rpt);
4687
4688 if (hal_status == RTW_HAL_STATUS_SUCCESS) {
4689 _hal_mac_ax_ppdu_sts_to_hal_ppdu_sts(&ppdu_rpt, ppdu_sts);
4690 _hal_mac_ax_ppdu_sts_to_hal_info(hal_info ,&ppdu_rpt,
4691 rx_mdata);
4692 }
4693
4694 return hal_status;
4695 }
4696
4697
4698 /**
4699 * the function to enable HW header conversion function
4700 * @hal_info: see struct hal_info_t
4701 * @en_hdr_conv: true to enable, false to disable
4702 *
4703 * return RTW_HAL_STATUS_MAC_API_FAILURE if update fail
4704 */
rtw_hal_hdr_conv_cfg(struct hal_info_t * hal_info,u8 en_hdr_conv)4705 enum rtw_hal_status rtw_hal_hdr_conv_cfg(struct hal_info_t *hal_info,
4706 u8 en_hdr_conv)
4707 {
4708 enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
4709 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4710 u32 ret = 0;
4711
4712 ret = mac->ops->hdr_conv(mac, en_hdr_conv);
4713
4714 if (MACSUCCESS == ret) {
4715 sts = RTW_HAL_STATUS_SUCCESS;
4716 } else {
4717 PHL_TRACE(COMP_PHL_MAC, _PHL_WARNING_, "hdr_conv fail (0x%08X)\n",
4718 ret);
4719 sts = RTW_HAL_STATUS_MAC_API_FAILURE;
4720 }
4721
4722 return sts;
4723 }
4724
4725
4726 #ifdef RTW_PHL_BCN //fill hal mac ops
4727 enum rtw_hal_status
hal_mac_ax_config_beacon(struct hal_info_t * hal,struct rtw_bcn_entry * bcn_entry)4728 hal_mac_ax_config_beacon(struct hal_info_t *hal, struct rtw_bcn_entry *bcn_entry)
4729 {
4730 struct mac_ax_adapter *mac = hal_to_mac(hal);
4731 struct rtw_bcn_info_cmn *bcn_cmn = bcn_entry->bcn_cmn;
4732 struct rtw_bcn_info_hw *bcn_hw = &bcn_entry->bcn_hw;
4733 enum mac_ax_port_cfg_type ptype;
4734 struct mac_ax_port_cfg_para ppara = {0};
4735
4736 ppara.band = bcn_hw->band;
4737 ppara.port = bcn_hw->port;
4738 ppara.mbssid_idx = bcn_hw->mbssid;
4739
4740 ptype = MAC_AX_PCFG_BCN_INTV;
4741 ppara.val = bcn_cmn->bcn_interval;
4742 if (mac->ops->port_cfg(mac, ptype, &ppara) != MACSUCCESS)
4743 return RTW_HAL_STATUS_FAILURE;
4744
4745 ptype = MAC_AX_PCFG_HIQ_DTIM;
4746 ppara.val = bcn_cmn->bcn_dtim;
4747 if (mac->ops->port_cfg(mac, ptype, &ppara) != MACSUCCESS)
4748 return RTW_HAL_STATUS_FAILURE;
4749
4750 return RTW_HAL_STATUS_SUCCESS;
4751 }
4752
4753 enum rtw_hal_status
hal_mac_ax_send_beacon(struct hal_info_t * hal,struct rtw_bcn_entry * bcn_entry)4754 hal_mac_ax_send_beacon(struct hal_info_t *hal, struct rtw_bcn_entry *bcn_entry)
4755 {
4756
4757 struct mac_ax_adapter *mac = hal_to_mac(hal);
4758 struct rtw_bcn_info_cmn *bcn_cmn = bcn_entry->bcn_cmn;
4759 struct rtw_bcn_info_hw *bcn_hw = &bcn_entry->bcn_hw;
4760 struct mac_ax_bcn_info info = {0};
4761
4762 if(!mac->ops->send_bcn_h2c)
4763 return RTW_HAL_STATUS_FAILURE;
4764
4765 info.pld_buf = bcn_cmn->bcn_buf;
4766 info.pld_len = (u16)bcn_cmn->bcn_length;
4767
4768 info.band = bcn_hw->band;
4769 info.port = bcn_hw->port;
4770 info.mbssid = bcn_hw->mbssid;
4771 info.grp_ie_ofst = (u8)bcn_cmn->ie_offset_tim;
4772 info.macid = bcn_hw->mac_id;
4773
4774 if(bcn_cmn->bcn_offload & BIT(BCN_HW_TIM))
4775 info.grp_ie_ofst |= BIT(7);
4776
4777 if(bcn_cmn->bcn_offload & BIT(BCN_HW_SEQ)){
4778 info.ssn_sel = 1;
4779 info.ssn_mode = 1;
4780 }
4781 else {
4782 info.ssn_sel = 0;
4783 info.ssn_mode = 0;
4784 }
4785
4786 info.rate_sel = (u16)bcn_cmn->bcn_rate;
4787
4788 mac->ops->send_bcn_h2c(mac, &info);
4789
4790 return RTW_HAL_STATUS_SUCCESS;
4791
4792 }
4793 #endif //RTW_PHL_BCN
4794
4795 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)4796 rtw_hal_mac_ppdu_stat_cfg(struct hal_info_t *hal_info,
4797 u8 band_idx,
4798 bool ppdu_stat_en,
4799 u8 appen_info,
4800 u8 filter)
4801 {
4802 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4803 struct mac_ax_phy_rpt_cfg cfg = {0};
4804
4805 cfg.en = ppdu_stat_en;
4806 cfg.type = MAC_AX_PPDU_STATUS;
4807 /*cfg.dest = MAC_AX_PRPT_DEST_HOST;*/
4808
4809 cfg.u.ppdu.band = band_idx;
4810 if (ppdu_stat_en) {
4811 if (appen_info&HAL_PPDU_MAC_INFO)
4812 cfg.u.ppdu.bmp_append_info |= MAC_AX_PPDU_MAC_INFO;
4813 if (appen_info&HAL_PPDU_PLCP)
4814 cfg.u.ppdu.bmp_append_info |= MAC_AX_PPDU_PLCP;
4815 if (appen_info&HAL_PPDU_RX_CNT)
4816 cfg.u.ppdu.bmp_append_info |= MAC_AX_PPDU_RX_CNT;
4817
4818 if (filter&HAL_PPDU_HAS_A1M)
4819 cfg.u.ppdu.bmp_filter |= MAC_AX_PPDU_HAS_A1M;
4820 if (filter&HAL_PPDU_HAS_CRC_OK)
4821 cfg.u.ppdu.bmp_filter |= MAC_AX_PPDU_HAS_CRC_OK;
4822
4823 cfg.u.ppdu.dup2fw_en = false;
4824 cfg.u.ppdu.dup2fw_len = 0;
4825 }
4826
4827 if (mac->ops->cfg_phy_rpt(mac, &cfg) != MACSUCCESS) {
4828 PHL_ERR("%s fault\n", __func__);
4829 return RTW_HAL_STATUS_FAILURE;
4830 }
4831 return RTW_HAL_STATUS_SUCCESS;
4832 }
4833
rtw_hal_mac_config_hw_mgnt_sec(struct hal_info_t * hal_info,u8 en)4834 enum rtw_hal_status rtw_hal_mac_config_hw_mgnt_sec(struct hal_info_t *hal_info, u8 en)
4835 {
4836 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4837 struct mac_ax_ops *hal_mac_ops = mac->ops;
4838
4839 hal_mac_ops->sta_hw_security_support(mac, SEC_UC_MGNT_ENC, en);
4840 hal_mac_ops->sta_hw_security_support(mac, SEC_BMC_MGNT_ENC, en);
4841
4842 return RTW_HAL_STATUS_SUCCESS;
4843 }
4844
rtw_hal_mac_get_append_fcs(struct hal_info_t * hal_info,u8 * val)4845 enum rtw_hal_status rtw_hal_mac_get_append_fcs(struct hal_info_t *hal_info, u8 *val)
4846 {
4847 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4848 struct mac_ax_ops *ops = mac->ops;
4849
4850 if (ops->get_hw_value(mac, MAC_AX_HW_GET_APP_FCS, val) != MACSUCCESS)
4851 return RTW_HAL_STATUS_FAILURE;
4852 else
4853 return RTW_HAL_STATUS_SUCCESS;
4854 }
4855
rtw_hal_mac_get_acpt_icv_err(struct hal_info_t * hal_info,u8 * val)4856 enum rtw_hal_status rtw_hal_mac_get_acpt_icv_err(struct hal_info_t *hal_info, u8 *val)
4857 {
4858 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
4859 struct mac_ax_ops *ops = mac->ops;
4860
4861 if (ops->get_hw_value(mac, MAC_AX_HW_GET_RX_ICVERR, val) != MACSUCCESS)
4862 return RTW_HAL_STATUS_FAILURE;
4863 else
4864 return RTW_HAL_STATUS_SUCCESS;
4865 }
4866
4867 #ifdef CONFIG_PHL_CHANNEL_INFO
4868 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)4869 rtw_hal_mac_chan_info_cfg(struct hal_info_t *hal_info,
4870 bool chinfo_en, u8 macid,
4871 u8 mode, u8 filter, u8 sg_size)
4872 {
4873 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4874 struct mac_ax_phy_rpt_cfg cfg = {0};
4875
4876 cfg.en = chinfo_en;
4877 cfg.type = MAC_AX_CH_INFO;
4878 /*cfg.dest = MAC_AX_PRPT_DEST_HOST;*/
4879 cfg.u.chif.macid = macid;
4880
4881 if (chinfo_en) {
4882 /*ToDo - mode*/
4883 cfg.u.chif.trigger = MAC_AX_CH_INFO_MACID;
4884 /*ToDo - filter*/
4885 cfg.u.chif.bmp_filter = MAC_AX_CH_INFO_DATA_FRM;
4886 cfg.u.chif.dis_to = 0;
4887 /*ToDo - sg_size*/
4888 cfg.u.chif.seg_size = MAC_AX_CH_IFNO_SEG_512;
4889 }
4890 if (mac->ops->cfg_phy_rpt(mac, &cfg) != MACSUCCESS) {
4891 PHL_ERR("%s fault\n", __func__);
4892 return RTW_HAL_STATUS_FAILURE;
4893 }
4894 return RTW_HAL_STATUS_SUCCESS;
4895 }
4896 #endif /* CONFIG_PHL_CHANNEL_INFO */
4897
rtw_hal_mac_dbg_status_dump(struct hal_info_t * hal,struct hal_mac_dbg_dump_cfg * cfg)4898 void rtw_hal_mac_dbg_status_dump(struct hal_info_t *hal, struct hal_mac_dbg_dump_cfg *cfg)
4899 {
4900 struct mac_ax_adapter *mac = hal_to_mac(hal);
4901 struct mac_ax_dbgpkg pkg = {0};
4902 struct mac_ax_dbgpkg_en pkg_en = {0};
4903
4904 pkg.ss_dbg_0 = cfg->ss_dbg_0;
4905 pkg.ss_dbg_1 = cfg->ss_dbg_1;
4906
4907 pkg_en.ss_dbg = cfg->ss_dbg;
4908 pkg_en.dle_dbg = cfg->dle_dbg;
4909 pkg_en.dmac_dbg = cfg->dmac_dbg;
4910 pkg_en.cmac_dbg = cfg->cmac_dbg;
4911 pkg_en.mac_dbg_port = cfg->mac_dbg_port;
4912 pkg_en.plersvd_dbg = cfg->plersvd_dbg;
4913 pkg_en.tx_flow_dbg = cfg->tx_flow_dbg;
4914
4915 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);
4916 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);
4917 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);
4918
4919 mac->ops->dbg_status_dump(mac, &pkg, &pkg_en);
4920 }
4921
4922 #ifdef CONFIG_PHL_DFS
4923 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)4924 rtw_hal_mac_dfs_rpt_cfg(struct hal_info_t *hal_info,
4925 bool rpt_en, u8 rpt_num, u8 rpt_to)
4926 {
4927 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4928 struct mac_ax_phy_rpt_cfg cfg = {0};
4929
4930 cfg.en = rpt_en;
4931 cfg.type = MAC_AX_DFS;
4932 /*cfg.dest = MAC_AX_PRPT_DEST_HOST;*/
4933
4934 if (rpt_en) {
4935 cfg.u.dfs.num_th = rpt_num;
4936 cfg.u.dfs.en_timeout = rpt_to;
4937 }
4938
4939 if (mac->ops->cfg_phy_rpt(mac, &cfg) != MACSUCCESS) {
4940 PHL_ERR("%s fault\n", __func__);
4941 return RTW_HAL_STATUS_FAILURE;
4942 }
4943 return RTW_HAL_STATUS_SUCCESS;
4944 }
4945
4946 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)4947 rtw_hal_mac_parse_dfs(struct hal_info_t *hal_info,
4948 u8 *buf, u32 buf_len, struct mac_ax_dfs_rpt *dfs_rpt)
4949 {
4950 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4951
4952 if (mac->ops->parse_dfs(mac, buf, buf_len, dfs_rpt) != MACSUCCESS) {
4953 PHL_ERR("%s fault\n", __func__);
4954 return RTW_HAL_STATUS_FAILURE;
4955 }
4956
4957 return RTW_HAL_STATUS_SUCCESS;
4958 }
4959 #endif /*CONFIG_PHL_DFS*/
4960
4961 enum rtw_hal_status
_hal_mac_get_pkt_ofld(struct hal_info_t * hal_info,u8 * id)4962 _hal_mac_get_pkt_ofld(struct hal_info_t *hal_info, u8 *id)
4963 {
4964 struct rtw_hal_com_t *hal_com = hal_info->hal_com;
4965 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4966 u8 *pkt_buf = NULL;
4967 u16 pkt_len;
4968
4969 if(mac == NULL)
4970 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
4971
4972 if (mac->ops->pkt_ofld_packet(mac, &pkt_buf, &pkt_len, id) != MACSUCCESS)
4973 return RTW_HAL_STATUS_FAILURE;
4974
4975 debug_dump_data((u8 *)pkt_buf, pkt_len, "pkt ofld");
4976
4977 _os_mem_free(hal_com->drv_priv, pkt_buf, pkt_len);
4978
4979 return RTW_HAL_STATUS_SUCCESS;
4980 }
4981
4982 enum rtw_hal_status
_hal_mac_chk_pkt_ofld(struct hal_info_t * hal_info)4983 _hal_mac_chk_pkt_ofld(struct hal_info_t *hal_info)
4984 {
4985 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
4986 void *d = hal_to_drvpriv(hal_info);
4987 u16 loop_cnt = 0;
4988
4989 if(mac == NULL)
4990 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
4991
4992 do
4993 {
4994 if (mac->ops->check_fwofld_done(mac, 1) == MACSUCCESS)
4995 break;
4996
4997 _os_sleep_ms(d, POLLING_HALMAC_TIME);
4998
4999 loop_cnt++;
5000 } while (loop_cnt < POLLING_HALMAC_CNT);
5001
5002 if ( loop_cnt < POLLING_HALMAC_CNT) {
5003 PHL_PRINT("%s, check count = %d.\n", __func__, loop_cnt);
5004 return RTW_HAL_STATUS_SUCCESS;
5005 } else {
5006 PHL_ERR("%s, polling timeout!!!\n", __func__);
5007 return RTW_HAL_STATUS_FAILURE;
5008 }
5009 }
5010
5011 enum rtw_hal_status
_hal_mac_add_pkt_ofld(struct hal_info_t * hal_info,u8 * pkt,u16 len,u8 * id)5012 _hal_mac_add_pkt_ofld(struct hal_info_t *hal_info, u8 *pkt, u16 len, u8 *id)
5013 {
5014 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5015 u32 status;
5016
5017 if(mac == NULL)
5018 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5019
5020 PHL_PRINT("%s: len %d.\n", __func__, len);
5021
5022 status = mac->ops->add_pkt_ofld(mac, pkt, len, id);
5023 if (status != MACSUCCESS) {
5024 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5025 return RTW_HAL_STATUS_FAILURE;
5026 }
5027 PHL_PRINT("%s: id %d.\n", __func__, *id);
5028
5029 status = _hal_mac_chk_pkt_ofld(hal_info);
5030 return status;
5031 }
5032
5033 enum rtw_hal_status
_hal_mac_del_pkt_ofld(struct hal_info_t * hal_info,u8 * id)5034 _hal_mac_del_pkt_ofld(struct hal_info_t *hal_info, u8 *id)
5035 {
5036 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5037 u32 status;
5038
5039 if(mac == NULL)
5040 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5041
5042 PHL_PRINT("%s: id %d.\n", __func__, *id);
5043
5044 status = mac->ops->del_pkt_ofld(mac, *id);
5045 if (status != MACSUCCESS) {
5046 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5047 return RTW_HAL_STATUS_FAILURE;
5048 }
5049
5050 status = _hal_mac_chk_pkt_ofld(hal_info);
5051 return RTW_HAL_STATUS_SUCCESS;
5052 }
5053
5054 enum rtw_hal_status
_hal_mac_read_pkt_ofld(struct hal_info_t * hal_info,u8 * id)5055 _hal_mac_read_pkt_ofld(struct hal_info_t *hal_info, u8 *id)
5056 {
5057 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5058 u32 status;
5059
5060 if(mac == NULL)
5061 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5062
5063 PHL_PRINT("%s: id %d.\n", __func__, *id);
5064
5065 status = mac->ops->read_pkt_ofld(mac, *id);
5066 if (status != MACSUCCESS) {
5067 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5068 return RTW_HAL_STATUS_FAILURE;
5069 }
5070
5071 status = _hal_mac_chk_pkt_ofld(hal_info);
5072 if (status != MACSUCCESS) {
5073 return RTW_HAL_STATUS_FAILURE;
5074 }
5075
5076 status = _hal_mac_get_pkt_ofld(hal_info, id);
5077 return RTW_HAL_STATUS_SUCCESS;
5078 }
5079
rtw_hal_mac_pkt_ofld(struct hal_info_t * hal,u8 * id,u8 op,u8 * pkt,u16 * len)5080 enum rtw_hal_status rtw_hal_mac_pkt_ofld(struct hal_info_t *hal, u8 *id, u8 op,
5081 u8 *pkt, u16 *len)
5082 {
5083 enum rtw_hal_status status = RTW_HAL_STATUS_FAILURE;
5084
5085 switch(op) {
5086 case PKT_OFLD_ADD:
5087 status = _hal_mac_add_pkt_ofld(hal, pkt, *len, id);
5088 break;
5089
5090 case PKT_OFLD_DEL:
5091 status = _hal_mac_del_pkt_ofld(hal, id);
5092 break;
5093
5094 case PKT_OFLD_READ:
5095 status = _hal_mac_read_pkt_ofld(hal, id);
5096 break;
5097
5098 default:
5099 PHL_ERR("%s op(%d) not define.\n", __func__, op);
5100 break;
5101 }
5102
5103 return status;
5104 }
5105
rtw_hal_mac_pkt_update_ids(struct hal_info_t * hal,struct pkt_ofld_entry * entry)5106 enum rtw_hal_status rtw_hal_mac_pkt_update_ids(struct hal_info_t *hal,
5107 struct pkt_ofld_entry *entry)
5108 {
5109 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal->mac;
5110 struct mac_ax_general_pkt_ids mac_ids = {0};
5111 u32 status;
5112
5113 mac_ids.macid = (u8)entry->macid;
5114 mac_ids.probersp = entry->pkt_info[PKT_TYPE_PROBE_RSP].id;
5115 mac_ids.pspoll = entry->pkt_info[PKT_TYPE_PS_POLL].id;
5116 mac_ids.nulldata = entry->pkt_info[PKT_TYPE_NULL_DATA].id;
5117 mac_ids.qosnull = entry->pkt_info[PKT_TYPE_QOS_NULL].id;
5118 mac_ids.cts2self = entry->pkt_info[PKT_TYPE_CTS2SELF].id;
5119
5120 PHL_PRINT("macid %d, probersp %d, pspoll %d, nulldata %d, qosnull %d, cts2self %d.\n",
5121 mac_ids.macid,
5122 mac_ids.probersp,
5123 mac_ids.pspoll,
5124 mac_ids.nulldata,
5125 mac_ids.qosnull,
5126 mac_ids.cts2self);
5127
5128 status = mac->ops->general_pkt_ids(mac, &mac_ids);
5129 if (status != MACSUCCESS) {
5130 PHL_ERR("%s fault, status = %d.\n", __func__, status);
5131 return RTW_HAL_STATUS_FAILURE;
5132 }
5133 return status;
5134 }
5135 enum rtw_hal_status
rtw_hal_mac_reset_pkt_ofld_state(struct hal_info_t * hal_info)5136 rtw_hal_mac_reset_pkt_ofld_state(struct hal_info_t *hal_info)
5137 {
5138 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
5139
5140 if (mac == NULL)
5141 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
5142
5143 if (mac->ops->reset_fwofld_state(mac, 1) != MACSUCCESS)
5144 return RTW_HAL_STATUS_FAILURE;
5145 else
5146 return RTW_HAL_STATUS_SUCCESS;
5147
5148 }
5149
5150 /* comment temporary and review it later */
5151 #if 0
5152 u4Byte hal_mac_ax_dbg_h2cpkt_lb(RT_HAL_MAC_INFO *hm_info, u32 size)
5153 {
5154 PADAPTER adapter = hm_info->adapter;
5155 u32 ret = 0;
5156
5157 u8 *h2cbuf = NULL;
5158 FunctionIn(COMP_HAL_MAC_API);
5159
5160 //ret = hm_info->halmac_ax_ops->fwcmd_lb(hm_info->halmac_ax_apter,
5161 // 100, 0);
5162
5163 PlatformAllocateMemory(adapter, (PVOID *)&h2cbuf, size);
5164 PlatformZeroMemory(h2cbuf,size);
5165
5166 for (u4Byte tmpc = 0; tmpc < size - 32; tmpc++) {
5167 h2cbuf[32 + tmpc] = (u8)tmpc & 0xFF;
5168 }
5169
5170 hal_mac_ax_send_h2c_pkt(adapter, h2cbuf, size);
5171
5172 PlatformFreeMemory(h2cbuf, size);
5173
5174 FunctionOut(COMP_HAL_MAC_API);
5175 return ret;
5176 }
5177
5178
5179 u4Byte hal_mac_ax_update_table_dl_swru(RT_HAL_MAC_INFO *hm_info,
5180 struct ofdma_dl_group *dl_group)
5181 {
5182 PADAPTER adapter = hm_info->adapter;
5183 u32 ret=0;
5184 FunctionIn(COMP_HAL_MAC_API);
5185
5186 ret = hm_info->halmac_ax_ops->upd_dlru_grptbl(
5187 hm_info->halmac_ax_apter,
5188 &dl_group->dl_grp_table);
5189
5190
5191 FunctionOut(COMP_HAL_MAC_API);
5192 return ret;
5193 }
5194
5195 u4Byte hal_mac_ax_update_table_dl_swfix(RT_HAL_MAC_INFO *hm_info,
5196 struct ofdma_dl_group *dl_group)
5197 {
5198 PADAPTER adapter = hm_info->adapter;
5199 u32 ret=0;
5200 FunctionIn(COMP_HAL_MAC_API);
5201
5202 ret = hm_info->halmac_ax_ops->upd_dlru_fixtbl(
5203 hm_info->halmac_ax_apter,
5204 &dl_group->fixed_mode_group);
5205
5206
5207 FunctionOut(COMP_HAL_MAC_API);
5208 return ret;
5209 }
5210
5211
5212 u4Byte hal_mac_ax_update_table_ul_rufix(RT_HAL_MAC_INFO *hm_info,
5213 struct ofdma_ul_group *ul_group)
5214 {
5215 PADAPTER adapter = hm_info->adapter;
5216 u32 ret=0;
5217 FunctionIn(COMP_HAL_MAC_API);
5218
5219 ret = hm_info->halmac_ax_ops->upd_ulru_fixtbl(
5220 hm_info->halmac_ax_apter,
5221 &ul_group->fixed_mode_group);
5222
5223 FunctionOut(COMP_HAL_MAC_API);
5224 return ret;
5225 }
5226
5227 u4Byte hal_mac_ax_update_table_ul_ru_table(RT_HAL_MAC_INFO *hm_info,
5228 struct ofdma_ul_group *ul_group)
5229 {
5230 PADAPTER adapter = hm_info->adapter;
5231 u32 ret=0;
5232 FunctionIn(COMP_HAL_MAC_API);
5233
5234 ret = hm_info->halmac_ax_ops->upd_ulru_grptbl(
5235 hm_info->halmac_ax_apter,
5236 &ul_group->ul_grp_table);
5237
5238 FunctionOut(COMP_HAL_MAC_API);
5239 return ret;
5240 }
5241
5242
5243 u4Byte hal_mac_ax_update_table_ul_drvfix(RT_HAL_MAC_INFO *hm_info,
5244 struct ofdma_ul_group *ul_group)
5245 {
5246 PADAPTER adapter = hm_info->adapter;
5247 u32 ret=0;
5248 FunctionIn(COMP_HAL_MAC_API);
5249
5250 ret = hm_info->halmac_ax_ops->upd_ul_fixinfo(
5251 hm_info->halmac_ax_apter,
5252 &ul_group->drv_fixed_info);
5253
5254 FunctionOut(COMP_HAL_MAC_API);
5255 return ret;
5256 }
5257
5258
5259 u4Byte hal_mac_ax_issue_bsrp(RT_HAL_MAC_INFO *hm_info,
5260 struct ofdma_ul_group *ul_group)
5261 {
5262 PADAPTER adapter = hm_info->adapter;
5263 u32 ret=0;
5264 FunctionIn(COMP_HAL_MAC_API);
5265
5266 ret = hm_info->halmac_ax_ops->upd_ul_fixinfo(
5267 hm_info->halmac_ax_apter,
5268 &ul_group->drv_fixed_info
5269 );
5270
5271 FunctionOut(COMP_HAL_MAC_API);
5272 return ret;
5273 }
5274
5275
5276 u4Byte hal_mac_ax_update_ru_sta(RT_HAL_MAC_INFO *hm_info,
5277 u8 *ru_sta_info)
5278 {
5279 /* upd_rusta_info */
5280 struct mac_ax_bb_stainfo *bb_stainfo = (struct mac_ax_bb_stainfo *)ru_sta_info;
5281
5282 hm_info->halmac_ax_ops->upd_rusta_info(
5283 hm_info->halmac_ax_apter,
5284 bb_stainfo
5285 );
5286 return 0;
5287 }
5288
5289 u4Byte hal_mac_ax_update_ba_info_table(RT_HAL_MAC_INFO *hm_info,
5290 u8 ba_info)
5291 {
5292 /* upd_ba_infotbl */
5293 struct mac_ax_ba_infotbl *ba_info_tbl = (struct mac_ax_ba_infotbl *)ba_info;
5294
5295 hm_info->halmac_ax_ops->upd_ba_infotbl(
5296 hm_info->halmac_ax_apter,
5297 ba_info_tbl
5298 );
5299
5300 return 0;
5301 }
5302
5303 u4Byte hal_mac_ax_Test_H2C(RT_HAL_MAC_INFO *hm_info,
5304 u32 length, u8 Burst)
5305 {
5306
5307 u32 ret =0;
5308 FunctionIn(COMP_HAL_MAC_API);
5309 ret = hm_info->halmac_ax_ops->fwcmd_lb(
5310 hm_info->halmac_ax_apter,
5311 length,
5312 Burst
5313 );
5314
5315
5316 FunctionOut(COMP_HAL_MAC_API);
5317
5318 return ret;
5319 }
5320
5321 u4Byte hal_mac_ax_compare_h2c_c2h(RT_HAL_MAC_INFO *hm_info,
5322 u8 *buf, u32 len)
5323 {
5324 u32 ret=0;
5325 FunctionIn(COMP_HAL_MAC_API);
5326 ret = hm_info->halmac_ax_ops->process_c2h(
5327 hm_info->halmac_ax_apter,
5328 buf,
5329 len
5330 );
5331 FunctionOut(COMP_HAL_MAC_API);
5332 return ret;
5333 }
5334 #endif
5335 //====================================================================
5336
5337 /*
5338 * halmac wrapper API for hal and proto type is at hal_api_mac.h
5339 * Efuse part.
5340 */
5341 enum rtw_hal_status
rtw_hal_mac_get_log_efuse_size(struct rtw_hal_com_t * hal_com,u32 * val,bool is_limited)5342 rtw_hal_mac_get_log_efuse_size(struct rtw_hal_com_t *hal_com, u32 *val,
5343 bool is_limited)
5344 {
5345 struct hal_info_t *hal_info = hal_com->hal_priv;
5346 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5347 if(is_limited == true) {
5348 if(mac->ops->get_hw_value(mac,
5349 MAC_AX_HW_GET_LIMIT_LOG_EFUSE_SIZE, val) != MACSUCCESS){
5350 PHL_ERR("%s: Get limited logical efuse size fail!\n",
5351 __FUNCTION__);
5352 return RTW_HAL_STATUS_FAILURE;
5353 }
5354 }
5355 else {
5356 if(mac->ops->get_hw_value(mac,
5357 MAC_AX_HW_GET_LOGICAL_EFUSE_SIZE, val) != MACSUCCESS){
5358 PHL_ERR("%s: Get logical efuse size fail!\n", __FUNCTION__);
5359 return RTW_HAL_STATUS_FAILURE;
5360 }
5361 }
5362 PHL_INFO("%s: Logical efuse size = %d!\n", __FUNCTION__, *val);
5363
5364 return RTW_HAL_STATUS_SUCCESS;
5365 }
5366
5367 enum rtw_hal_status
rtw_hal_mac_read_log_efuse_map(struct rtw_hal_com_t * hal_com,u8 * map,bool is_limited)5368 rtw_hal_mac_read_log_efuse_map(struct rtw_hal_com_t *hal_com, u8 *map,
5369 bool is_limited)
5370 {
5371 struct hal_info_t *hal_info = hal_com->hal_priv;
5372 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5373
5374 if (mac->ops->dump_log_efuse(mac,
5375 MAC_AX_EFUSE_PARSER_MAP,
5376 #ifdef RTW_WKARD_EFUSE_OPERATION
5377 MAC_AX_EFUSE_R_DRV,
5378 #else
5379 MAC_AX_EFUSE_R_AUTO,
5380 #endif
5381 map,
5382 is_limited
5383 ) != MACSUCCESS) {
5384 PHL_INFO("%s: Dump logical efuse fail!\n", __FUNCTION__);
5385 return RTW_HAL_STATUS_FAILURE;
5386 }
5387
5388 PHL_INFO("%s: Dump logical efuse ok!\n", __FUNCTION__);
5389 return RTW_HAL_STATUS_SUCCESS;
5390 }
5391
5392 /*
5393 * HALMAC PG EFUSE API put version length at the tail of map/mask buffer
5394 */
5395
5396 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)5397 rtw_hal_mac_write_log_efuse_map(struct rtw_hal_com_t *hal_com,
5398 u8 *map,
5399 u32 map_size,
5400 u8 *mask,
5401 u32 mask_size,
5402 u8 *map_version,
5403 u8 *mask_version,
5404 u8 version_length,
5405 u8 part,
5406 bool is_limited)
5407 {
5408 struct hal_info_t *hal_info = hal_com->hal_priv;
5409 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5410 struct mac_ax_pg_efuse_info info;
5411 enum rtw_hal_status status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
5412 u8 *tmp_map = NULL;
5413 u8 *tmp_mask = NULL;
5414
5415 tmp_map = _os_mem_alloc(hal_com->drv_priv, (map_size + version_length));
5416 if(tmp_map == NULL) {
5417 PHL_WARN("%s: Allocate pg map buffer fail!\n", __FUNCTION__);
5418 status = RTW_HAL_STATUS_RESOURCE;
5419 goto err_mem_tmp_map;
5420 }
5421
5422 tmp_mask = _os_mem_alloc(hal_com->drv_priv, (mask_size + version_length));
5423 if(tmp_mask == NULL) {
5424 PHL_WARN("%s: Allocate pg mask buffer fail!\n", __FUNCTION__);
5425 status = RTW_HAL_STATUS_RESOURCE;
5426 goto err_mem_tmp_mask;
5427 }
5428
5429 /* Copy efuse map and map version to tmp_map buffer */
5430 _os_mem_cpy(hal_com->drv_priv, tmp_map, map, map_size);
5431 _os_mem_cpy(hal_com->drv_priv, tmp_map+map_size, map_version,
5432 version_length);
5433 /* Copy efuse mask and mask version to tmp_mask buffer */
5434 _os_mem_cpy(hal_com->drv_priv, tmp_mask, mask, mask_size);
5435 _os_mem_cpy(hal_com->drv_priv, tmp_mask+mask_size, mask_version,
5436 version_length);
5437 #if 0 /* For debug usage */
5438 debug_dump_data(map, (u16)map_size, "logical map:");
5439 debug_dump_data(map_version, version_length, "logical map version:");
5440 debug_dump_data(mask, (u16)mask_size, "mask:");
5441 debug_dump_data(mask_version, version_length, "mask version:");
5442 debug_dump_data(tmp_map, (u16)(map_size + version_length), "tmp_map:");
5443 debug_dump_data(tmp_mask, (u16)(mask_size + version_length), "tmp_mask:");
5444 #endif
5445 info.efuse_map = tmp_map;
5446 info.efuse_map_size = map_size;
5447 info.efuse_mask = tmp_mask;
5448 info.efuse_mask_size= mask_size;
5449
5450 if (mac->ops->pg_efuse_by_map(mac,
5451 &info,
5452 MAC_AX_EFUSE_R_DRV,
5453 part,
5454 is_limited) != MACSUCCESS) {
5455 PHL_INFO("%s: PG Fail!\n", __FUNCTION__);
5456 status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
5457 }
5458 else {
5459 PHL_INFO("%s: PG ok!\n", __FUNCTION__);
5460 status = RTW_HAL_STATUS_SUCCESS;
5461 }
5462 _os_mem_free(hal_com->drv_priv, tmp_map, (map_size + version_length));
5463 _os_mem_free(hal_com->drv_priv, tmp_mask, (mask_size + version_length));
5464
5465 return status;
5466
5467 err_mem_tmp_mask:
5468 _os_mem_free(hal_com->drv_priv, tmp_map, (map_size + version_length));
5469
5470 err_mem_tmp_map:
5471
5472 return status;
5473 }
5474
5475
5476 enum rtw_hal_status
rtw_hal_mac_read_hidden_rpt(struct rtw_hal_com_t * hal_com)5477 rtw_hal_mac_read_hidden_rpt(struct rtw_hal_com_t *hal_com)
5478 {
5479
5480 struct hal_info_t *hal_info = hal_com->hal_priv;
5481 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5482 struct mac_defeature_value rpt;
5483 u32 err;
5484
5485 err = mac->ops->read_hidden_rpt(mac, &rpt);
5486 if (err != MACSUCCESS) {
5487 PHL_TRACE(COMP_PHL_TRIG, _PHL_INFO_, "err=0x%x\n", err);
5488 return RTW_HAL_STATUS_FAILURE;
5489 }
5490
5491 if (rpt.tx_spatial_stream != 7 && rpt.tx_spatial_stream > 0) {
5492 hal_com->phy_hw_cap[0].tx_num = rpt.tx_spatial_stream;
5493 hal_com->phy_hw_cap[1].tx_num = rpt.tx_spatial_stream;
5494 hal_com->rfpath_tx_num = rpt.tx_spatial_stream;
5495 }
5496 if (rpt.rx_spatial_stream != 7 && rpt.rx_spatial_stream > 0) {
5497 hal_com->phy_hw_cap[0].rx_num = rpt.rx_spatial_stream;
5498 hal_com->phy_hw_cap[1].rx_num = rpt.rx_spatial_stream;
5499 hal_com->rfpath_rx_num = rpt.rx_spatial_stream;
5500 }
5501 if (rpt.hw_special_type > EFUSE_HW_STYPE_NONE &&
5502 rpt.hw_special_type < EFUSE_HW_STYPE_GENERAL)
5503 hal_com->dev_hw_cap.hw_stype_cap = rpt.hw_special_type;
5504
5505 if (rpt.wl_func_support > EFUSE_WL_FUNC_NONE &&
5506 rpt.wl_func_support < EFUSE_WL_FUNC_GENERAL)
5507 hal_com->dev_hw_cap.wl_func_cap = rpt.wl_func_support;
5508
5509 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden tx=%d hidden rx=%d\n",
5510 rpt.tx_spatial_stream, rpt.rx_spatial_stream);
5511 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden bw=%d\n", rpt.bandwidth);
5512 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden protocol = %d\n",
5513 rpt.protocol_80211);
5514 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden nic=%d\n", rpt.NIC_router);
5515 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden hw special type=%d\n",
5516 rpt.hw_special_type);
5517 PHL_TRACE(COMP_PHL_MAC, _PHL_INFO_, "hidden wl func=%d\n",
5518 rpt.wl_func_support);
5519 PHL_INFO("%s\n", __FUNCTION__);
5520 return RTW_HAL_STATUS_SUCCESS;
5521 }
5522
5523
5524 enum rtw_hal_status
rtw_hal_mac_check_efuse_autoload(struct rtw_hal_com_t * hal_com,u8 * autoload)5525 rtw_hal_mac_check_efuse_autoload(struct rtw_hal_com_t *hal_com, u8 *autoload)
5526 {
5527 struct hal_info_t *hal_info = hal_com->hal_priv;
5528 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5529
5530 if (mac->ops->check_efuse_autoload(mac, autoload) != MACSUCCESS)
5531 return RTW_HAL_STATUS_FAILURE;
5532
5533 if(*autoload == true)
5534 PHL_INFO("%s: efuse auto load SUCCESS!\n", __FUNCTION__);
5535 else
5536 PHL_INFO("%s: efuse auto load FAIL!\n", __FUNCTION__);
5537
5538 return RTW_HAL_STATUS_SUCCESS;
5539 }
5540
5541 enum rtw_hal_status
rtw_hal_mac_get_efuse_avl(struct rtw_hal_com_t * hal_com,u32 * val)5542 rtw_hal_mac_get_efuse_avl(struct rtw_hal_com_t *hal_com, u32 *val)
5543 {
5544 struct hal_info_t *hal_info = hal_com->hal_priv;
5545 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5546
5547 if (mac->ops->get_efuse_avl_size(mac, val) != MACSUCCESS)
5548 return RTW_HAL_STATUS_FAILURE;
5549
5550 PHL_INFO("%s\n", __FUNCTION__);
5551 return RTW_HAL_STATUS_SUCCESS;
5552 }
5553
5554 enum rtw_hal_status
rtw_hal_mac_get_efuse_size(struct rtw_hal_com_t * hal_com,u32 * val)5555 rtw_hal_mac_get_efuse_size(struct rtw_hal_com_t *hal_com, u32 *val)
5556 {
5557 struct hal_info_t *hal_info = hal_com->hal_priv;
5558 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5559
5560 if (mac->ops->get_hw_value(mac,
5561 MAC_AX_HW_GET_EFUSE_SIZE, val) != MACSUCCESS){
5562 PHL_ERR("%s: Get efuse size fail!\n", __FUNCTION__);
5563 return RTW_HAL_STATUS_FAILURE;
5564 }
5565 PHL_INFO("%s: Efuse size = %d!\n", __FUNCTION__, *val);
5566
5567 return RTW_HAL_STATUS_SUCCESS;
5568 }
5569
5570 enum rtw_hal_status
rtw_hal_mac_get_efuse_mask_size(struct rtw_hal_com_t * hal_com,u32 * val,bool is_limited)5571 rtw_hal_mac_get_efuse_mask_size(struct rtw_hal_com_t *hal_com, u32 *val,
5572 bool is_limited)
5573 {
5574 struct hal_info_t *hal_info = hal_com->hal_priv;
5575 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5576
5577 if(is_limited == true) {
5578 if(mac->ops->get_hw_value(mac,
5579 MAC_AX_HW_GET_LIMIT_EFUSE_MASK_SIZE, val) != MACSUCCESS)
5580 return RTW_HAL_STATUS_FAILURE;
5581 }
5582 else {
5583 if(mac->ops->get_hw_value(mac,
5584 MAC_AX_HW_GET_EFUSE_MASK_SIZE, val) != MACSUCCESS)
5585 return RTW_HAL_STATUS_FAILURE;
5586 }
5587
5588 PHL_INFO("%s: efuse mask size = %d\n", __FUNCTION__, *val);
5589 return RTW_HAL_STATUS_SUCCESS;
5590 }
5591
5592 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)5593 rtw_hal_mac_get_efuse_info(struct rtw_hal_com_t *hal_com,
5594 u8 *efuse_map, enum rtw_efuse_info info_type, void *value,
5595 u8 size, u8 map_valid)
5596 {
5597 struct hal_info_t *hal_info = hal_com->hal_priv;
5598 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5599
5600 PHL_INFO("%s\n", __FUNCTION__);
5601
5602 if (mac->ops->get_efuse_info(mac, efuse_map, info_type, value, size,
5603 &map_valid) != MACSUCCESS)
5604 return RTW_HAL_STATUS_FAILURE;
5605 return RTW_HAL_STATUS_SUCCESS;
5606 }
5607
5608 enum rtw_hal_status
rtw_hal_mac_read_phy_efuse(struct rtw_hal_com_t * hal_com,u32 addr,u32 size,u8 * value)5609 rtw_hal_mac_read_phy_efuse(struct rtw_hal_com_t *hal_com,
5610 u32 addr, u32 size, u8 *value)
5611 {
5612 struct hal_info_t *hal_info = hal_com->hal_priv;
5613 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5614
5615 PHL_INFO("%s\n", __FUNCTION__);
5616
5617 if (mac->ops->read_efuse(mac, addr, size, value,
5618 MAC_AX_EFUSE_BANK_WIFI) != MACSUCCESS)
5619 return RTW_HAL_STATUS_FAILURE;
5620 return RTW_HAL_STATUS_SUCCESS;
5621 }
5622
5623 enum rtw_hal_status
rtw_hal_mac_read_bt_phy_efuse(struct rtw_hal_com_t * hal_com,u32 addr,u32 size,u8 * value)5624 rtw_hal_mac_read_bt_phy_efuse(struct rtw_hal_com_t *hal_com,
5625 u32 addr, u32 size, u8 *value)
5626 {
5627 struct hal_info_t *hal_info = hal_com->hal_priv;
5628 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5629
5630 PHL_INFO("%s\n", __FUNCTION__);
5631
5632 if (mac->ops->read_efuse(mac, addr, size, value,
5633 MAC_AX_EFUSE_BANK_BT) != MACSUCCESS)
5634 return RTW_HAL_STATUS_FAILURE;
5635 return RTW_HAL_STATUS_SUCCESS;
5636 }
5637
rtw_hal_mac_write_msk_pwr_reg(struct rtw_hal_com_t * hal_com,u8 band,u32 offset,u32 mask,u32 val)5638 u32 rtw_hal_mac_write_msk_pwr_reg(
5639 struct rtw_hal_com_t *hal_com, u8 band, u32 offset, u32 mask, 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_msk_pwr_reg(mac, band, offset, mask, val);
5647
5648 if (result != MACSUCCESS)
5649 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_,
5650 "Write power register failure, status = %d\n", result);
5651
5652 return result;
5653 }
5654
rtw_hal_mac_set_pwr_reg(struct rtw_hal_com_t * hal_com,u8 band,u32 offset,u32 val)5655 u32 rtw_hal_mac_set_pwr_reg(struct rtw_hal_com_t *hal_com, u8 band, u32 offset, u32 val){
5656
5657 struct hal_info_t *hal = hal_com->hal_priv;
5658 struct mac_ax_adapter *mac = hal_to_mac(hal);
5659 struct mac_ax_ops *ops = mac->ops;
5660 u32 result = 0;
5661
5662 result = ops->write_pwr_reg(mac, band, offset, val);
5663
5664 if (result != MACSUCCESS)
5665 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set power register failure, status = %d\n", result);
5666
5667 return result;
5668 }
5669
rtw_hal_mac_get_pwr_reg(struct rtw_hal_com_t * hal_com,u8 band,u32 offset,u32 * val)5670 u32 rtw_hal_mac_get_pwr_reg(struct rtw_hal_com_t *hal_com, u8 band, u32 offset, u32 *val){
5671 struct hal_info_t *hal = hal_com->hal_priv;
5672 struct mac_ax_adapter *mac = hal_to_mac(hal);
5673 struct mac_ax_ops *ops = mac->ops;
5674 u32 result = 0;
5675
5676 result = ops->read_pwr_reg(mac, band, offset, val);
5677
5678 if (result != MACSUCCESS)
5679 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Get power register failure, status = %d\n", result);
5680
5681 return result;
5682 }
5683
5684 enum rtw_hal_status
rtw_hal_mac_get_xcap(struct rtw_hal_com_t * hal_com,u8 sc_xo,u32 * value)5685 rtw_hal_mac_get_xcap(struct rtw_hal_com_t *hal_com, u8 sc_xo, u32 *value){
5686 struct hal_info_t *hal_info = hal_com->hal_priv;
5687 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5688 struct mac_ax_ops *ops = mac->ops;
5689 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5690
5691 ret = ops->read_xcap_reg(mac, sc_xo, value);
5692
5693 if (ret != MACSUCCESS)
5694 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Get xacp failure, status = %d\n", ret);
5695
5696 return ret;
5697 }
5698
5699 enum rtw_hal_status
rtw_hal_mac_set_xcap(struct rtw_hal_com_t * hal_com,u8 sc_xo,u32 value)5700 rtw_hal_mac_set_xcap(struct rtw_hal_com_t *hal_com, u8 sc_xo, u32 value){
5701 struct hal_info_t *hal_info = hal_com->hal_priv;
5702 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5703 struct mac_ax_ops *ops = mac->ops;
5704 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5705
5706 ret = ops->write_xcap_reg(mac, sc_xo, value);
5707
5708 if (ret != MACSUCCESS)
5709 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set xacp failure, status = %d\n", ret);
5710
5711 return ret;
5712 }
5713
5714 enum rtw_hal_status
rtw_hal_mac_get_xsi(struct rtw_hal_com_t * hal_com,u8 offset,u8 * val)5715 rtw_hal_mac_get_xsi(struct rtw_hal_com_t *hal_com, u8 offset, u8* val)
5716 {
5717 struct hal_info_t *hal_info = hal_com->hal_priv;
5718 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5719
5720 /* Because mac si function is not support mac ops*/
5721 /* we call mac si function temporarily until mac team feedback.*/
5722 if (mac_read_xtal_si(mac, offset, val) != MACSUCCESS) {
5723 PHL_INFO("Get xsi failure, status = %s\n", __FUNCTION__);
5724 return RTW_HAL_STATUS_FAILURE;
5725 }
5726
5727 PHL_INFO("%s\n", __FUNCTION__);
5728 return RTW_HAL_STATUS_SUCCESS;
5729 }
5730
5731 enum rtw_hal_status
rtw_hal_mac_set_xsi(struct rtw_hal_com_t * hal_com,u8 offset,u8 val)5732 rtw_hal_mac_set_xsi(struct rtw_hal_com_t *hal_com, u8 offset, u8 val)
5733 {
5734 struct hal_info_t *hal_info = hal_com->hal_priv;
5735 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5736
5737 /* Because mac si function is not support mac ops*/
5738 /* we call mac si function temporarily until mac team feedback.*/
5739 if (mac_write_xtal_si(mac, offset, val, 0xff) != MACSUCCESS) {
5740 PHL_INFO("Set xsi failure, status = %s\n", __FUNCTION__);
5741 return RTW_HAL_STATUS_FAILURE;
5742 }
5743
5744 PHL_INFO("%s\n", __FUNCTION__);
5745 return RTW_HAL_STATUS_SUCCESS;
5746 }
5747
5748
5749 enum rtw_hal_status
rtw_hal_mac_fw_dbg_dump(struct hal_info_t * hal_info)5750 rtw_hal_mac_fw_dbg_dump(struct hal_info_t *hal_info)
5751 {
5752 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5753 u8 *buffer = NULL;
5754 u16 bufSize = FW_PLE_SIZE;
5755 struct mac_ax_fwdbg_en en;
5756 u32 mac_err = 0;
5757
5758 en.status_dbg = 1;
5759 en.ps_dbg = 1;
5760 en.rsv_ple_dbg = 0;
5761
5762 mac_err = mac->ops->fw_dbg_dump(mac, &buffer, &en);
5763 if (mac_err != MACSUCCESS) {
5764 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
5765 return RTW_HAL_STATUS_FAILURE;
5766 }
5767
5768 if (en.rsv_ple_dbg && buffer) {
5769 /*fw buffer is 2048, but Windows DbgPrint only 512 Bytes, so we split buffer to 4 segments*/
5770 if (buffer != NULL) {
5771 PHL_PRINT("=======================\n");
5772 PHL_PRINT("Start to dump fw rsvd ple:\n\n");
5773 _hal_fw_dbg_dump(hal_info, buffer, bufSize);
5774 PHL_PRINT("\n=======================\n");
5775 }
5776 }
5777 if (buffer != NULL)
5778 _os_mem_free(hal_info->hal_com->drv_priv, buffer, bufSize);
5779
5780 return RTW_HAL_STATUS_SUCCESS;
5781 }
5782
5783 enum rtw_hal_status
rtw_hal_mac_ps_notify_wake(struct hal_info_t * hal_info)5784 rtw_hal_mac_ps_notify_wake(struct hal_info_t *hal_info)
5785 {
5786 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5787
5788 if (mac->ops->ps_notify_wake(mac) == MACSUCCESS) {
5789 return RTW_HAL_STATUS_SUCCESS;
5790 } else {
5791 PHL_WARN("%s: notify wake fail!\n", __FUNCTION__);
5792 return RTW_HAL_STATUS_FAILURE;
5793 }
5794 }
5795
5796 enum rtw_hal_status
rtw_hal_mac_req_pwr_state(struct hal_info_t * hal_info,u8 pwr_state)5797 rtw_hal_mac_req_pwr_state(struct hal_info_t *hal_info, u8 pwr_state)
5798 {
5799 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5800
5801 if(mac->ops->ps_pwr_state(mac, MAC_AX_PWR_STATE_ACT_REQ, pwr_state)
5802 == MACSUCCESS)
5803 return RTW_HAL_STATUS_SUCCESS;
5804 else
5805 return RTW_HAL_STATUS_FAILURE;
5806 }
5807
5808 enum rtw_hal_status
rtw_hal_mac_chk_pwr_state(struct hal_info_t * hal_info,u8 pwr_state,u32 * mac_sts)5809 rtw_hal_mac_chk_pwr_state(struct hal_info_t *hal_info, u8 pwr_state, u32 *mac_sts)
5810 {
5811 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5812
5813 *mac_sts = mac->ops->ps_pwr_state(mac, MAC_AX_PWR_STATE_ACT_CHK, pwr_state);
5814 if(*mac_sts == MACSUCCESS)
5815 return RTW_HAL_STATUS_SUCCESS;
5816 else
5817 return RTW_HAL_STATUS_FAILURE;
5818 }
5819
5820 enum rtw_hal_status
rtw_hal_mac_ips_cfg(struct hal_info_t * hal_info,u16 macid,bool enable)5821 rtw_hal_mac_ips_cfg(struct hal_info_t *hal_info, u16 macid, bool enable)
5822 {
5823 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5824
5825 if (mac->ops->cfg_ips(mac, (u8)macid, enable) == MACSUCCESS)
5826 return RTW_HAL_STATUS_SUCCESS;
5827 else
5828 return RTW_HAL_STATUS_FAILURE;
5829 }
5830
5831 enum rtw_hal_status
rtw_hal_mac_ips_chk_leave(struct hal_info_t * hal_info,u16 macid)5832 rtw_hal_mac_ips_chk_leave(struct hal_info_t *hal_info, u16 macid)
5833 {
5834 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5835
5836 if (mac->ops->chk_leave_ips(mac, (u8)macid) == MACSUCCESS)
5837 return RTW_HAL_STATUS_SUCCESS;
5838 else
5839 return RTW_HAL_STATUS_FAILURE;
5840 }
5841
5842 enum rtw_hal_status
rtw_hal_mac_lps_cfg(struct hal_info_t * hal_info,struct rtw_hal_lps_info * lps_info)5843 rtw_hal_mac_lps_cfg(struct hal_info_t *hal_info,
5844 struct rtw_hal_lps_info *lps_info)
5845 {
5846 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5847 enum mac_ax_ps_mode ax_ps_mode;
5848 struct mac_ax_lps_info ax_lps_info;
5849
5850 if (lps_info->en) {
5851 ax_ps_mode = MAC_AX_PS_MODE_LEGACY;
5852 } else {
5853 ax_ps_mode = MAC_AX_PS_MODE_ACTIVE;
5854 }
5855
5856 ax_lps_info.listen_bcn_mode = lps_info->listen_bcn_mode;
5857 ax_lps_info.awake_interval = lps_info->awake_interval;
5858 ax_lps_info.smart_ps_mode = lps_info->smart_ps_mode;
5859
5860 if (mac->ops->cfg_lps(mac, (u8)lps_info->macid, ax_ps_mode,
5861 &ax_lps_info) == MACSUCCESS)
5862 return RTW_HAL_STATUS_SUCCESS;
5863 else
5864 return RTW_HAL_STATUS_FAILURE;
5865 }
5866
5867 enum rtw_hal_status
rtw_hal_mac_lps_chk_leave(struct hal_info_t * hal_info,u16 macid,u32 * mac_sts)5868 rtw_hal_mac_lps_chk_leave(struct hal_info_t *hal_info, u16 macid, u32 *mac_sts)
5869 {
5870 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5871
5872 *mac_sts = mac->ops->chk_leave_lps(mac, (u8)macid);
5873 if(*mac_sts == MACSUCCESS)
5874 return RTW_HAL_STATUS_SUCCESS;
5875 else
5876 return RTW_HAL_STATUS_FAILURE;
5877 }
5878
5879 enum rtw_hal_status
rtw_hal_mac_lps_chk_access(struct hal_info_t * hal_info,u32 offset)5880 rtw_hal_mac_lps_chk_access(struct hal_info_t *hal_info, u32 offset)
5881 {
5882 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5883
5884 if(mac->ops->io_chk_access(mac, offset) == MACSUCCESS)
5885 return RTW_HAL_STATUS_SUCCESS;
5886 else
5887 return RTW_HAL_STATUS_FAILURE;
5888 }
5889
5890 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)5891 rtw_hal_mac_get_rx_cnt(struct hal_info_t *hal_info, u8 cur_phy_idx, u8 type_idx, u32 *ret_value){
5892 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5893 struct mac_ax_ops *ops = mac->ops;
5894 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5895
5896 struct mac_ax_rx_cnt rx_cnt;
5897 u16 rx_cnt_buff[MAC_AX_RX_PPDU_MAX];
5898 u32 rx_cnt_total=0;
5899 u16 ppdu_idx;
5900
5901 rx_cnt.type = type_idx;
5902 rx_cnt.op = MAC_AX_RXCNT_R;
5903 rx_cnt.buf = rx_cnt_buff;
5904 rx_cnt.band = cur_phy_idx;
5905
5906 ret = ops->rx_cnt(mac, &rx_cnt);
5907
5908 for(ppdu_idx=0;ppdu_idx<MAC_AX_RX_PPDU_MAX;ppdu_idx++)
5909 {
5910 rx_cnt_total+=rx_cnt_buff[ppdu_idx];
5911 }
5912
5913 *ret_value = rx_cnt_total;
5914
5915 if (ret != MACSUCCESS){
5916 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "mac get rx counter fail, status=%d\n",ret);
5917 }
5918
5919 return ret;
5920 }
5921
5922 enum rtw_hal_status
rtw_hal_mac_set_reset_rx_cnt(struct hal_info_t * hal_info,u8 cur_phy_idx)5923 rtw_hal_mac_set_reset_rx_cnt(struct hal_info_t *hal_info, u8 cur_phy_idx)
5924 {
5925 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
5926 struct mac_ax_ops *ops = mac->ops;
5927 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
5928
5929 struct mac_ax_rx_cnt rx_cnt;
5930 u16 rx_cnt_buff[MAC_AX_RX_PPDU_MAX];
5931
5932 rx_cnt.type = MAC_AX_RX_IDX;
5933 rx_cnt.op = MAC_AX_RXCNT_RST_ALL;
5934 rx_cnt.buf = rx_cnt_buff;
5935 rx_cnt.band = cur_phy_idx;
5936
5937 ret = ops->rx_cnt(mac, &rx_cnt);
5938
5939 if (ret != MACSUCCESS){
5940 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "mac reset rx cnt fail, status=%d\n",ret);
5941 }
5942
5943 return ret;
5944 }
5945
5946 enum rtw_hal_status
rtw_hal_mac_tx_idle_poll(struct rtw_hal_com_t * hal_com,u8 band_idx)5947 rtw_hal_mac_tx_idle_poll(struct rtw_hal_com_t *hal_com, u8 band_idx)
5948 {
5949 struct hal_info_t *hal = hal_com->hal_priv;
5950 struct mac_ax_adapter *mac = hal_to_mac(hal);
5951 struct mac_ax_tx_idle_poll_cfg cfg = {0};
5952 u32 err = 0;
5953
5954
5955 cfg.sel = MAC_AX_TX_IDLE_POLL_SEL_BAND;
5956 cfg.band = band_idx;
5957 err = mac->ops->tx_idle_poll(mac, &cfg);
5958 if (err != MACSUCCESS) {
5959 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_,
5960 "Polling tx idle failure(%d)!\n", err);
5961 return RTW_HAL_STATUS_TIMEOUT;
5962 }
5963
5964 return RTW_HAL_STATUS_SUCCESS;
5965 }
5966
5967 enum rtw_sch_txen_cfg {
5968 RTW_TXEN_BE0 = 1 << 0,
5969 RTW_TXEN_BK0 = 1 << 1,
5970 RTW_TXEN_VI0 = 1 << 2,
5971 RTW_TXEN_VO0 = 1 << 3,
5972 RTW_TXEN_BE1 = 1 << 4,
5973 RTW_TXEN_BK1 = 1 << 5,
5974 RTW_TXEN_VI1 = 1 << 6,
5975 RTW_TXEN_VO1 = 1 << 7,
5976 RTW_TXEN_MG0 = 1 << 8,
5977 RTW_TXEN_MG1 = 1 << 9,
5978 RTW_TXEN_MG2 = 1 << 10,
5979 RTW_TXEN_HI = 1 << 11,
5980 RTW_TXEN_BCN = 1 << 12,
5981 RTW_TXEN_UL = 1 << 13,
5982 RTW_TXEN_TWT0 = 1 << 14,
5983 RTW_TXEN_TWT1 = 1 << 15,
5984 RTW_TXEN_DRV_MASK = 0x19FF,
5985 RTW_TXEN_ALL = 0xFFFF,
5986 };
5987
5988 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)5989 rtw_hal_mac_set_sch_tx_en(struct rtw_hal_com_t *hal_com, u8 band_idx,
5990 u16 tx_en, u16 tx_en_mask)
5991 {
5992 struct hal_info_t *hal = hal_com->hal_priv;
5993 struct mac_ax_adapter *mac = hal_to_mac(hal);
5994 struct mac_ax_ops *ops = mac->ops;
5995 struct mac_ax_sch_tx_en_cfg cfg;
5996 enum rtw_hal_status ret;
5997 u32 result = 0;
5998
5999 ret = RTW_HAL_STATUS_SUCCESS;
6000 cfg.band = band_idx;
6001
6002 cfg.tx_en.be0 = ((tx_en & RTW_TXEN_BE0) ? 1 : 0);
6003 cfg.tx_en.bk0 = ((tx_en & RTW_TXEN_BK0) ? 1 : 0);
6004 cfg.tx_en.vi0 = ((tx_en & RTW_TXEN_VI0) ? 1 : 0);
6005 cfg.tx_en.vo0 = ((tx_en & RTW_TXEN_VO0) ? 1 : 0);
6006 cfg.tx_en.be1 = ((tx_en & RTW_TXEN_BE1) ? 1 : 0);
6007 cfg.tx_en.bk1 = ((tx_en & RTW_TXEN_BK1) ? 1 : 0);
6008 cfg.tx_en.vi1 = ((tx_en & RTW_TXEN_VI1) ? 1 : 0);
6009 cfg.tx_en.vo1 = ((tx_en & RTW_TXEN_VO1) ? 1 : 0);
6010 cfg.tx_en.mg0 = ((tx_en & RTW_TXEN_MG0) ? 1 : 0);
6011 cfg.tx_en.mg1 = ((tx_en & RTW_TXEN_MG1) ? 1 : 0);
6012 cfg.tx_en.mg2 = ((tx_en & RTW_TXEN_MG2) ? 1 : 0);
6013 cfg.tx_en.hi = ((tx_en & RTW_TXEN_HI) ? 1 : 0);
6014 cfg.tx_en.bcn = ((tx_en & RTW_TXEN_BCN) ? 1 : 0);
6015 cfg.tx_en.ul = ((tx_en & RTW_TXEN_UL) ? 1 : 0);
6016 cfg.tx_en.twt0 = ((tx_en & RTW_TXEN_TWT0) ? 1 : 0);
6017 cfg.tx_en.twt1 = ((tx_en & RTW_TXEN_TWT1) ? 1 : 0);
6018
6019 cfg.tx_en_mask.be0 = ((tx_en_mask & RTW_TXEN_BE0) ? 1 : 0);
6020 cfg.tx_en_mask.bk0 = ((tx_en_mask & RTW_TXEN_BK0) ? 1 : 0);
6021 cfg.tx_en_mask.vi0 = ((tx_en_mask & RTW_TXEN_VI0) ? 1 : 0);
6022 cfg.tx_en_mask.vo0 = ((tx_en_mask & RTW_TXEN_VO0) ? 1 : 0);
6023 cfg.tx_en_mask.be1 = ((tx_en_mask & RTW_TXEN_BE1) ? 1 : 0);
6024 cfg.tx_en_mask.bk1 = ((tx_en_mask & RTW_TXEN_BK1) ? 1 : 0);
6025 cfg.tx_en_mask.vi1 = ((tx_en_mask & RTW_TXEN_VI1) ? 1 : 0);
6026 cfg.tx_en_mask.vo1 = ((tx_en_mask & RTW_TXEN_VO1) ? 1 : 0);
6027 cfg.tx_en_mask.mg0 = ((tx_en_mask & RTW_TXEN_MG0) ? 1 : 0);
6028 cfg.tx_en_mask.mg1 = ((tx_en_mask & RTW_TXEN_MG1) ? 1 : 0);
6029 cfg.tx_en_mask.mg2 = ((tx_en_mask & RTW_TXEN_MG2) ? 1 : 0);
6030 cfg.tx_en_mask.hi = ((tx_en_mask & RTW_TXEN_HI) ? 1 : 0);
6031 cfg.tx_en_mask.bcn = ((tx_en_mask & RTW_TXEN_BCN) ? 1 : 0);
6032 cfg.tx_en_mask.ul = ((tx_en_mask & RTW_TXEN_UL) ? 1 : 0);
6033 cfg.tx_en_mask.twt0 = ((tx_en_mask & RTW_TXEN_TWT0) ? 1 : 0);
6034 cfg.tx_en_mask.twt1 = ((tx_en_mask & RTW_TXEN_TWT1) ? 1 : 0);
6035
6036 result = ops->set_hw_value(mac, MAC_AX_HW_SET_SCH_TXEN_CFG, &cfg);
6037
6038 if (result != MACSUCCESS) {
6039 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set Tx pause failure, status = %d\n", result);
6040 ret = RTW_HAL_STATUS_FAILURE;
6041 }
6042
6043 return ret;
6044 }
6045
6046 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)6047 rtw_hal_tx_pause(struct rtw_hal_com_t *hal_com,
6048 u8 band_idx, bool tx_pause, enum tx_pause_rson rson)
6049 {
6050 u16 *tx_off;
6051 enum tx_pause_rson i;
6052 u16 tx_cfg = 0;
6053 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
6054
6055
6056 tx_off = &hal_com->band[band_idx].tx_pause[rson];
6057 if (tx_pause == true) {
6058 switch (rson) {
6059 case PAUSE_RSON_NOR_SCAN:
6060 *tx_off = (u16)~RTW_TXEN_MG0;
6061 break;
6062 case PAUSE_RSON_RFK:
6063 case PAUSE_RSON_PSD:
6064 case PAUSE_RSON_DFS:
6065 case PAUSE_RSON_DBCC:
6066 case PAUSE_RSON_RESET:
6067 *tx_off = (u16)RTW_TXEN_ALL;
6068 break;
6069 default:
6070 PHL_ERR("Unknow pause reason:%d\n", rson);
6071 goto _error;
6072 }
6073 } else {
6074 *tx_off = 0;
6075 }
6076
6077 tx_off = hal_com->band[band_idx].tx_pause;
6078 for (i = 0; (i < PAUSE_RSON_MAX) && (tx_cfg != RTW_TXEN_ALL); i++)
6079 if (tx_off[i])
6080 tx_cfg |= tx_off[i];
6081 /* tx_cfg is white list, but tx_pause of struct rtw_hw_band is black list */
6082 tx_cfg = ~tx_cfg;
6083 PHL_INFO("TX %sPause - Reason(%d) for band-%u, final tx_cfg(0x%04x)\n",
6084 tx_pause?"":"Un-", rson, band_idx, tx_cfg);
6085
6086 hstatus = rtw_hal_mac_set_sch_tx_en(hal_com, band_idx,
6087 tx_cfg, RTW_TXEN_ALL);
6088 if (hstatus != RTW_HAL_STATUS_SUCCESS)
6089 goto _error;
6090
6091 if ((rson == PAUSE_RSON_RFK) && tx_pause) {
6092 hstatus = rtw_hal_mac_tx_idle_poll(hal_com, band_idx);
6093 if (hstatus != RTW_HAL_STATUS_SUCCESS)
6094 goto _error;
6095 }
6096
6097 _error:
6098 return hstatus;
6099 }
6100
6101 enum rtw_hal_status
rtw_hal_mac_set_macid_pause(struct rtw_hal_com_t * hal_com,u16 macid,bool pause)6102 rtw_hal_mac_set_macid_pause(struct rtw_hal_com_t *hal_com,
6103 u16 macid, bool pause)
6104 {
6105 struct hal_info_t *hal = hal_com->hal_priv;
6106 struct mac_ax_adapter *mac = hal_to_mac(hal);
6107 struct mac_ax_ops *ops = mac->ops;
6108 struct mac_ax_macid_pause_cfg cfg = {0};
6109 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
6110
6111 cfg.macid = (u8)macid;
6112 cfg.pause = pause;
6113
6114 PHL_INFO("%s macid:%d(%s) \n", __func__, macid, pause ? "pause":"unpause");
6115 /*TODO - MAC_AX_HW_SET_MULTI_ID_PAUSE*/
6116 if (ops->set_hw_value(mac, MAC_AX_HW_SET_ID_PAUSE, &cfg) != MACSUCCESS) {
6117 PHL_ERR("%s failed\n", __func__);
6118 hstatus = RTW_HAL_STATUS_FAILURE;
6119 }
6120
6121 return hstatus;
6122 }
6123
6124 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)6125 rtw_hal_mac_set_macid_grp_pause(struct rtw_hal_com_t *hal_com,
6126 u32 *macid_arr, u8 macid_arr_sz, bool pause)
6127 {
6128 struct hal_info_t *hal = hal_com->hal_priv;
6129 struct mac_ax_adapter *mac = hal_to_mac(hal);
6130 struct mac_ax_ops *ops = mac->ops;
6131 struct mac_ax_macid_pause_grp cfg = {0};
6132 enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
6133 u8 pause_grp_sz = 0, mac_grp_sz = 0, arr_idx = 0, bit_idx = 0;
6134 u32 mac_ret = MACSUCCESS;
6135
6136 /* size check */
6137 mac_grp_sz = sizeof(cfg.pause_grp) / sizeof(cfg.pause_grp[0]);
6138 pause_grp_sz = MIN(mac_grp_sz, macid_arr_sz);
6139
6140 for (arr_idx = 0; arr_idx < pause_grp_sz; arr_idx++) {
6141 for (bit_idx = 0; bit_idx < 32; bit_idx++) {
6142 if (macid_arr[arr_idx] & BIT(bit_idx)) {
6143 cfg.mask_grp[arr_idx] |= BIT(bit_idx);
6144 if (pause)
6145 cfg.pause_grp[arr_idx] |= BIT(bit_idx);
6146 else
6147 cfg.pause_grp[arr_idx] &= ~BIT(bit_idx);
6148 }
6149 }
6150 }
6151
6152 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__,
6153 cfg.pause_grp[0], cfg.pause_grp[1], cfg.pause_grp[2], cfg.pause_grp[3],
6154 cfg.mask_grp[0], cfg.mask_grp[1], cfg.mask_grp[2], cfg.mask_grp[3],
6155 pause ? "pause":"unpause");
6156
6157 mac_ret = ops->set_hw_value(mac, MAC_AX_HW_SET_MULTI_ID_PAUSE, &cfg);
6158 if (mac_ret != MACSUCCESS) {
6159 PHL_ERR("%s failed(mac ret:%d)\n", __func__, mac_ret);
6160 hstatus = RTW_HAL_STATUS_FAILURE;
6161 }
6162
6163 return hstatus;
6164 }
6165
6166 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)6167 rtw_hal_mac_fw_log_cfg(struct rtw_hal_com_t *hal_com,
6168 struct rtw_hal_fw_log_cfg *fl_cfg)
6169 {
6170 struct hal_info_t *hal = hal_com->hal_priv;
6171 struct mac_ax_adapter *mac = hal_to_mac(hal);
6172 struct mac_ax_fw_log log_cfg = {0};
6173 u32 status;
6174
6175 if(mac == NULL)
6176 return RTW_HAL_STATUS_MAC_INIT_FAILURE;
6177
6178 log_cfg.level = fl_cfg->level;
6179 log_cfg.output = fl_cfg->output;
6180 log_cfg.comp = fl_cfg->comp;
6181 log_cfg.comp_ext = fl_cfg->comp_ext;
6182
6183 PHL_PRINT("%s: level %d, output 0x%08x, comp 0x%08x, comp ext 0x%08x.\n",
6184 __func__,
6185 log_cfg.level,
6186 log_cfg.output,
6187 log_cfg.comp,
6188 log_cfg.comp_ext);
6189
6190 if(log_cfg.output == MAC_AX_FL_LV_UART)
6191 {
6192 mac->ops->pinmux_set_func(mac, MAC_AX_GPIO_UART_TX_GPIO5);
6193 mac->ops->sel_uart_tx_pin(mac, MAC_AX_UART_TX_GPIO5);
6194 mac->ops->pinmux_set_func(mac, MAC_AX_GPIO_UART_RX_GPIO6);
6195 mac->ops->sel_uart_rx_pin(mac, MAC_AX_UART_RX_GPIO6);
6196 }
6197
6198 status = mac->ops->fw_log_cfg(mac, &log_cfg);
6199 if (status != MACSUCCESS) {
6200 PHL_ERR("%s fault, status = %d.\n", __func__, status);
6201 return RTW_HAL_STATUS_FAILURE;
6202 }
6203 return RTW_HAL_STATUS_SUCCESS;
6204 }
6205
6206 u32
rtw_hal_mac_lamode_trig(struct rtw_hal_com_t * hal_com,u8 trig)6207 rtw_hal_mac_lamode_trig(struct rtw_hal_com_t *hal_com, u8 trig)
6208 {
6209 struct hal_info_t *hal_info = hal_com->hal_priv;
6210 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6211 u32 rpt = 0;
6212
6213 rpt = mac->ops->lamode_trigger(mac, trig);
6214
6215 return rpt;
6216 }
6217
6218 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)6219 rtw_hal_mac_lamode_cfg_buf(struct rtw_hal_com_t *hal_com, u8 buf_sel,
6220 u32 *addr_start, u32 *addr_end)
6221 {
6222 struct hal_info_t *hal_info = hal_com->hal_priv;
6223 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6224 struct mac_ax_la_buf_param param;
6225
6226 param.la_buf_sel = buf_sel;
6227
6228 mac->ops->lamode_buf_cfg(mac, ¶m);
6229
6230 *addr_start = param.start_addr;
6231 *addr_end = param.end_addr;
6232
6233 return RTW_HAL_STATUS_SUCCESS;
6234 }
6235
6236 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)6237 rtw_hal_mac_lamode_cfg(struct rtw_hal_com_t *hal_com, u8 func_en,
6238 u8 restart_en, u8 timeout_en, u8 timeout_val,
6239 u8 data_loss_imr, u8 la_tgr_tu_sel, u8 tgr_time_val)
6240 {
6241 struct hal_info_t *hal_info = hal_com->hal_priv;
6242 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6243 struct mac_ax_la_cfg cfg;
6244
6245 cfg.la_func_en = func_en;
6246 cfg.la_restart_en = restart_en;
6247 cfg.la_timeout_en = timeout_en;
6248 cfg.la_timeout_val = timeout_val;
6249 cfg.la_data_loss_imr = data_loss_imr;
6250 cfg.la_tgr_tu_sel = la_tgr_tu_sel;
6251 cfg.la_tgr_time_val = tgr_time_val;
6252
6253 mac->ops->lamode_cfg(mac, &cfg);
6254
6255 return RTW_HAL_STATUS_SUCCESS;
6256 }
6257
6258 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)6259 rtw_hal_mac_get_lamode_st(struct rtw_hal_com_t *hal_com, u8 *la_state,
6260 u16 *la_finish_addr, bool *la_round_up,
6261 bool *la_loss_data)
6262 {
6263 struct hal_info_t *hal_info = hal_com->hal_priv;
6264 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6265 struct mac_ax_la_status info;
6266
6267 info = mac->ops->get_lamode_st(mac);
6268
6269 *la_state = info.la_sw_fsmst;
6270 *la_finish_addr = info.la_buf_wptr;
6271 *la_round_up = info.la_buf_rndup_ind;
6272 *la_loss_data = info.la_data_loss;
6273
6274 return RTW_HAL_STATUS_SUCCESS;
6275 }
6276
_hal_set_dft_rxfltr(struct mac_ax_rx_fltr_ctrl_t * ctrl,struct mac_ax_rx_fltr_ctrl_t * mask)6277 static inline void _hal_set_dft_rxfltr(struct mac_ax_rx_fltr_ctrl_t *ctrl,
6278 struct mac_ax_rx_fltr_ctrl_t *mask)
6279 {
6280 /* filter packets by address */
6281 ctrl->sniffer_mode = 0;
6282 mask->sniffer_mode = 1;
6283
6284 /* check unicast */
6285 ctrl->acpt_a1_match_pkt = 1;
6286 mask->acpt_a1_match_pkt = 1;
6287 ctrl->uc_pkt_chk_cam_match = 1;
6288 mask->uc_pkt_chk_cam_match = 1;
6289
6290 /* check broadcast */
6291 ctrl->acpt_bc_pkt = 1;
6292 mask->acpt_bc_pkt = 1;
6293 ctrl->bc_pkt_chk_cam_match = 1;
6294 mask->bc_pkt_chk_cam_match = 1;
6295
6296 /* check multicast */
6297 ctrl->acpt_mc_pkt = 1;
6298 mask->acpt_mc_pkt = 1;
6299 /* black list filter */
6300 ctrl->mc_pkt_white_lst_mode = 0;
6301 mask->mc_pkt_white_lst_mode = 1;
6302
6303 /* check beacon */
6304 ctrl->bcn_chk_en = 1;
6305 mask->bcn_chk_en = 1;
6306 ctrl->bcn_chk_rule = 0; /* 2: A2&A3 match */
6307 mask->bcn_chk_rule = 0x3;
6308
6309 /* misc */
6310 ctrl->acpt_pwr_mngt_pkt = 1;
6311 mask->acpt_pwr_mngt_pkt = 1;
6312
6313 ctrl->acpt_ftm_req_pkt = 1;
6314 mask->acpt_ftm_req_pkt = 1;
6315 }
6316 /**
6317 * rtw_hal_mac_set_rxfltr_by_mode - Set rx filter option by scenario
6318 * @hal_com: pointer of struct rtw_hal_com_t
6319 * @band: 0x0: band0, 0x1: band1
6320 * @mode: scenario mode
6321 *
6322 * Set RX filter setting by scenario.
6323 *
6324 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6325 */
6326 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)6327 rtw_hal_mac_set_rxfltr_by_mode(struct rtw_hal_com_t *hal_com,
6328 u8 band, enum rtw_rx_fltr_mode mode)
6329 {
6330 struct hal_info_t *hal_info = hal_com->hal_priv;
6331 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6332 struct mac_ax_rx_fltr_ctrl_t ctrl = {0};
6333 struct mac_ax_rx_fltr_ctrl_t mask = {0};
6334 u32 err;
6335
6336
6337 switch (mode) {
6338 case RX_FLTR_MODE_RESTORE:
6339 break;
6340 case RX_FLTR_MODE_SNIFFER:
6341 ctrl.sniffer_mode = 1;
6342 mask.sniffer_mode = 1;
6343 break;
6344 case RX_FLTR_MODE_SCAN:
6345 ctrl.acpt_a1_match_pkt = 1;
6346 mask.acpt_a1_match_pkt = 1;
6347 ctrl.acpt_bc_pkt = 1;
6348 mask.acpt_bc_pkt = 1;
6349 ctrl.acpt_mc_pkt = 1;
6350 mask.acpt_mc_pkt = 1;
6351 ctrl.uc_pkt_chk_cam_match = 0;
6352 mask.uc_pkt_chk_cam_match = 1;
6353 ctrl.bc_pkt_chk_cam_match = 0;
6354 mask.bc_pkt_chk_cam_match = 1;
6355
6356 /* Do NOT check B_AX_A_BCN_CHK_RULE
6357 * when receiving beacon and probe_response
6358 */
6359 ctrl.bcn_chk_en = 0;
6360 mask.bcn_chk_en = 1;
6361 break;
6362 case RX_FLTR_MODE_STA_NORMAL:
6363 #if 1
6364 _hal_set_dft_rxfltr(&ctrl, &mask);
6365
6366 #else
6367 /* filter packets by address */
6368 ctrl.sniffer_mode = 0;
6369 mask.sniffer_mode = 1;
6370 /* check unicast */
6371 ctrl.acpt_a1_match_pkt = 1;
6372 mask.acpt_a1_match_pkt = 1;
6373 ctrl.uc_pkt_chk_cam_match = 1;
6374 mask.uc_pkt_chk_cam_match = 1;
6375 /* check broadcast */
6376 ctrl.acpt_bc_pkt = 1;
6377 mask.acpt_bc_pkt = 1;
6378 ctrl.bc_pkt_chk_cam_match = 1;
6379 mask.bc_pkt_chk_cam_match = 1;
6380
6381 if ((hal_com->chip_id == CHIP_WIFI6_8852A)
6382 && (hal_com->cv == CAV)) {
6383 /* don't check address cam for multicast, accept all */
6384 ctrl.acpt_mc_pkt = 0;
6385 mask.acpt_mc_pkt = 1;
6386 } else {
6387 /* check multicast */
6388 ctrl.acpt_mc_pkt = 1;
6389 mask.acpt_mc_pkt = 1;
6390 /* black list filter */
6391 ctrl.mc_pkt_white_lst_mode = 0;
6392 mask.mc_pkt_white_lst_mode = 1;
6393 }
6394 /* check beacon */
6395 ctrl.bcn_chk_en = 1;
6396 mask.bcn_chk_en = 1;
6397 ctrl.bcn_chk_rule = 2; /* 2: A2&A3 match */
6398 mask.bcn_chk_rule = 0x3;
6399 /* misc */
6400 ctrl.acpt_pwr_mngt_pkt = 1;
6401 mask.acpt_pwr_mngt_pkt = 1;
6402 ctrl.acpt_ftm_req_pkt = 1;
6403 mask.acpt_ftm_req_pkt = 1;
6404 #endif
6405 break;
6406 case RX_FLTR_MODE_STA_LINKING:
6407 #if 1
6408 _hal_set_dft_rxfltr(&ctrl, &mask);
6409 /* check broadcast */
6410 ctrl.acpt_bc_pkt = 1;
6411 mask.acpt_bc_pkt = 1;
6412 ctrl.bc_pkt_chk_cam_match = 0;
6413 mask.bc_pkt_chk_cam_match = 1;
6414
6415 /* check beacon */
6416 ctrl.bcn_chk_en = 0;
6417 mask.bcn_chk_en = 1;
6418
6419 #else
6420 /* filter packets by address */
6421 ctrl.sniffer_mode = 0;
6422 mask.sniffer_mode = 1;
6423 /* check unicast */
6424 ctrl.acpt_a1_match_pkt = 1;
6425 mask.acpt_a1_match_pkt = 1;
6426 ctrl.uc_pkt_chk_cam_match = 1;
6427 mask.uc_pkt_chk_cam_match = 1;
6428 /* check broadcast */
6429 ctrl.acpt_bc_pkt = 1;
6430 mask.acpt_bc_pkt = 1;
6431 ctrl.bc_pkt_chk_cam_match = 0;
6432 mask.bc_pkt_chk_cam_match = 1;
6433
6434 if ((hal_com->chip_id == CHIP_WIFI6_8852A)
6435 && (hal_com->cv == CAV)) {
6436 /* don't check address cam for multicast, accept all */
6437 ctrl.acpt_mc_pkt = 0;
6438 mask.acpt_mc_pkt = 1;
6439 } else {
6440 /* check multicast */
6441 ctrl.acpt_mc_pkt = 1;
6442 mask.acpt_mc_pkt = 1;
6443 /* black list filter */
6444 ctrl.mc_pkt_white_lst_mode = 0;
6445 mask.mc_pkt_white_lst_mode = 1;
6446 }
6447 /* check beacon */
6448 ctrl.bcn_chk_en = 0;
6449 mask.bcn_chk_en = 1;
6450 ctrl.bcn_chk_rule = 2; /* 2: A2&A3 match */
6451 mask.bcn_chk_rule = 0x3;
6452 /* misc */
6453 ctrl.acpt_pwr_mngt_pkt = 1;
6454 mask.acpt_pwr_mngt_pkt = 1;
6455 ctrl.acpt_ftm_req_pkt = 1;
6456 mask.acpt_ftm_req_pkt = 1;
6457 #endif
6458 break;
6459
6460 case RX_FLTR_MODE_AP_NORMAL:
6461 #if 1
6462 _hal_set_dft_rxfltr(&ctrl, &mask);
6463
6464 /* check unicast */
6465 ctrl.acpt_a1_match_pkt = 1;
6466 mask.acpt_a1_match_pkt = 1;
6467 ctrl.uc_pkt_chk_cam_match = 0;
6468 mask.uc_pkt_chk_cam_match = 1;
6469
6470 /* check broadcast (for probe req) */
6471 ctrl.acpt_bc_pkt = 1;
6472 mask.acpt_bc_pkt = 1;
6473 ctrl.bc_pkt_chk_cam_match = 0;
6474 mask.bc_pkt_chk_cam_match = 1;
6475
6476 #else
6477 /*
6478 * SNIFFER: OFF
6479 * UC address CAM A1: ON
6480 * UC addr CAM match: OFF
6481 * BC accept: ON
6482 * BC address CAM: OFF
6483 * Beacon check: OFF
6484 */
6485 /* filter packets by address */
6486 ctrl.sniffer_mode = 0;
6487 mask.sniffer_mode = 1;
6488 /* Unicast
6489 * Do not enable address CAM matching filtering but all A1
6490 * matched ones. AP should accept all UC requests from
6491 * unknown STAs.
6492 */
6493 ctrl.acpt_a1_match_pkt = 1;
6494 mask.acpt_a1_match_pkt = 1;
6495 ctrl.uc_pkt_chk_cam_match = 0;
6496 mask.uc_pkt_chk_cam_match = 1;
6497
6498 /* check broadcast (Probe req) */
6499 ctrl.acpt_bc_pkt = 1;
6500 mask.acpt_bc_pkt = 1;
6501 ctrl.bc_pkt_chk_cam_match = 0;
6502 mask.bc_pkt_chk_cam_match = 1;
6503
6504 if ((hal_com->chip_id == CHIP_WIFI6_8852A)
6505 && (hal_com->cv == CAV)) {
6506 /* don't check address cam for multicast, accept all */
6507 ctrl.acpt_mc_pkt = 1;
6508 mask.acpt_mc_pkt = 1;
6509 } else {
6510 /* check multicast */
6511 ctrl.acpt_mc_pkt = 1;
6512 mask.acpt_mc_pkt = 1;
6513 /* black list filter */
6514 ctrl.mc_pkt_white_lst_mode = 0;
6515 mask.mc_pkt_white_lst_mode = 1;
6516 }
6517
6518 /* check beacon */
6519 ctrl.bcn_chk_en = 1;
6520 mask.bcn_chk_en = 1;
6521 ctrl.bcn_chk_rule = 2; /* 2: A2&A3 match */
6522 mask.bcn_chk_rule = 0x3;
6523
6524 /* bcn_chk_rule
6525 0: A3 hit
6526 1: A2 hit
6527 2: A2 & A3 hit
6528 3: A2 | A3 hit
6529 */
6530 /* accept power management frame */
6531 ctrl.acpt_pwr_mngt_pkt = 1;
6532 mask.acpt_pwr_mngt_pkt = 1;
6533 ctrl.acpt_ftm_req_pkt = 1;
6534 mask.acpt_ftm_req_pkt = 1;
6535 #endif
6536 break;
6537
6538 }
6539
6540 err = mac->ops->set_rx_fltr_opt(mac, &ctrl, &mask, band);
6541 if (err)
6542 return RTW_HAL_STATUS_FAILURE;
6543
6544 return RTW_HAL_STATUS_SUCCESS;
6545 }
6546
6547 /**
6548 * rtw_hal_mac_set_rxfltr_acpt_crc_err - Accept CRC error packets or not
6549 * @hal_com: pointer of struct rtw_hal_com_t
6550 * @band: 0x0: band0, 0x1: band1
6551 * @enable: 0: deny, 1: accept
6552 *
6553 * Control accepting CRC error packets or not.
6554 *
6555 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6556 */
rtw_hal_mac_set_rxfltr_acpt_crc_err(struct rtw_hal_com_t * hal_com,u8 band,u8 enable)6557 enum rtw_hal_status rtw_hal_mac_set_rxfltr_acpt_crc_err(
6558 struct rtw_hal_com_t *hal_com, u8 band, u8 enable)
6559 {
6560 struct hal_info_t *hal_info = hal_com->hal_priv;
6561 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6562 struct mac_ax_rx_fltr_ctrl_t ctrl = {0};
6563 struct mac_ax_rx_fltr_ctrl_t mask = {0};
6564 u32 err;
6565
6566
6567 if (enable)
6568 ctrl.acpt_crc32_err_pkt = 1;
6569 else
6570 ctrl.acpt_crc32_err_pkt = 0;
6571 mask.acpt_crc32_err_pkt = 1;
6572
6573 err = mac->ops->set_rx_fltr_opt(mac, &ctrl, &mask, band);
6574 if (err)
6575 return RTW_HAL_STATUS_FAILURE;
6576
6577 return RTW_HAL_STATUS_SUCCESS;
6578 }
6579
6580 /**
6581 * rtw_hal_mac_set_rxfltr_mpdu_size - Set max MPDU size
6582 * @hal_com: pointer of struct rtw_hal_com_t
6583 * @band: 0x0: band0, 0x1: band1
6584 * @size: MPDU max size, unit: byte. 0 for no limit.
6585 *
6586 * MPDU size exceed Max size would be dropped.
6587 *
6588 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6589 */
rtw_hal_mac_set_rxfltr_mpdu_size(struct rtw_hal_com_t * hal_com,u8 band,u16 size)6590 enum rtw_hal_status rtw_hal_mac_set_rxfltr_mpdu_size(
6591 struct rtw_hal_com_t *hal_com, u8 band, u16 size)
6592 {
6593 struct hal_info_t *hal_info = hal_com->hal_priv;
6594 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6595 struct mac_ax_rx_fltr_ctrl_t ctrl = {0};
6596 struct mac_ax_rx_fltr_ctrl_t mask = {0};
6597 u32 err;
6598
6599
6600 /* unit of pkt_len_fltr is 512 bytes */
6601 ctrl.pkt_len_fltr = size >> 9;
6602 ctrl.pkt_len_fltr += (size & 0x7F) ? 1 : 0;
6603 mask.pkt_len_fltr = 0x3F;
6604
6605 err = mac->ops->set_rx_fltr_opt(mac, &ctrl, &mask, band);
6606 if (err)
6607 return RTW_HAL_STATUS_FAILURE;
6608
6609 return RTW_HAL_STATUS_SUCCESS;
6610 }
6611
6612 /**
6613 * rtw_hal_mac_set_rxfltr_by_type - Filter RX frame by frame type
6614 * @hal_com: pointer of struct rtw_hal_com_t
6615 * @band: 0x0: band0, 0x1: band1
6616 * @type: 802.11 frame type, b'00: mgmt, b'01: ctrl, b'10: data
6617 * @target: 0: drop, 1: accept(driver), 2: firmware
6618 *
6619 * Set RX filter setting by 802.11 frame type and frame would be dropped or
6620 * forward to specific target.
6621 *
6622 * Return RTW_HAL_STATUS_SUCCESS when setting is ok, otherwise fail.
6623 */
rtw_hal_mac_set_rxfltr_by_type(struct rtw_hal_com_t * hal_com,u8 band,u8 type,u8 target)6624 enum rtw_hal_status rtw_hal_mac_set_rxfltr_by_type(
6625 struct rtw_hal_com_t *hal_com, u8 band, u8 type, u8 target)
6626 {
6627 struct hal_info_t *hal_info = hal_com->hal_priv;
6628 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6629 enum mac_ax_pkt_t ftype;
6630 enum mac_ax_fwd_target fwd;
6631 u32 err;
6632
6633
6634 switch (type) {
6635 case RTW_PHL_PKT_TYPE_MGNT:
6636 ftype = MAC_AX_PKT_MGNT;
6637 break;
6638 case RTW_PHL_PKT_TYPE_CTRL:
6639 ftype = MAC_AX_PKT_CTRL;
6640 break;
6641 case RTW_PHL_PKT_TYPE_DATA:
6642 ftype = MAC_AX_PKT_DATA;
6643 break;
6644 default:
6645 return RTW_HAL_STATUS_FAILURE;
6646 }
6647
6648 if (target > MAC_AX_FWD_TO_WLAN_CPU)
6649 return RTW_HAL_STATUS_FAILURE;
6650 fwd = (enum mac_ax_fwd_target)target;
6651
6652 err = mac->ops->set_rx_fltr_typ_opt(mac, ftype, fwd, band);
6653 if (err)
6654 return RTW_HAL_STATUS_FAILURE;
6655
6656 return RTW_HAL_STATUS_SUCCESS;
6657 }
6658
6659 /**
6660 * rtw_hal_mac_set_rxfltr_by_subtype - Filter RX frame by frame type & subtype
6661 * @hal_com: pointer of struct rtw_hal_com_t
6662 * @band: 0x0: band0, 0x1: band1
6663 * @type: 802.11 frame type, b'00: mgmt, b'01: ctrl, b'10: data
6664 * @subtype: 802.11 frame subtype, value range is 0x00~0xFF.
6665 * @target: 0: drop, 1: accept(driver), 2: firmware
6666 *
6667 * Set RX filter setting by 802.11 frame type and subtype, then frame would be
6668 * dropped or forward to specific target.
6669 *
6670 * Return RTW_HAL_STATUS_SUCCESS when setting is ok, otherwise fail.
6671 */
rtw_hal_mac_set_rxfltr_by_subtype(struct rtw_hal_com_t * hal_com,u8 band,u8 type,u8 subtype,u8 target)6672 enum rtw_hal_status rtw_hal_mac_set_rxfltr_by_subtype(
6673 struct rtw_hal_com_t *hal_com, u8 band,
6674 u8 type, u8 subtype, u8 target)
6675 {
6676 struct hal_info_t *hal_info = hal_com->hal_priv;
6677 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6678 enum mac_ax_pkt_t ftype;
6679 enum mac_ax_fwd_target fwd;
6680 u32 err;
6681
6682
6683 switch (type) {
6684 case RTW_PHL_PKT_TYPE_MGNT:
6685 ftype = MAC_AX_PKT_MGNT;
6686 break;
6687 case RTW_PHL_PKT_TYPE_CTRL:
6688 ftype = MAC_AX_PKT_CTRL;
6689 break;
6690 case RTW_PHL_PKT_TYPE_DATA:
6691 ftype = MAC_AX_PKT_DATA;
6692 break;
6693 default:
6694 return RTW_HAL_STATUS_FAILURE;
6695 }
6696
6697 if (subtype > 0xFF)
6698 return RTW_HAL_STATUS_FAILURE;
6699
6700 if (target > MAC_AX_FWD_TO_WLAN_CPU)
6701 return RTW_HAL_STATUS_FAILURE;
6702 fwd = (enum mac_ax_fwd_target)target;
6703
6704 err = mac->ops->set_rx_fltr_typstyp_opt(mac, ftype, subtype, fwd, band);
6705 if (err)
6706 return RTW_HAL_STATUS_FAILURE;
6707 return RTW_HAL_STATUS_SUCCESS;
6708 }
6709
6710 enum rtw_hal_status
rtw_hal_mac_enable_bb_rf(struct hal_info_t * hal_info,u8 enable)6711 rtw_hal_mac_enable_bb_rf(struct hal_info_t *hal_info, u8 enable)
6712 {
6713 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
6714
6715 mac->ops->set_hw_value(mac, MAC_AX_HW_EN_BB_RF, &enable);
6716 return RTW_HAL_STATUS_SUCCESS;
6717 }
6718
6719 void
rtw_hal_mac_get_buffer_data(struct rtw_hal_com_t * hal_com,u32 strt_addr,u8 * buf,u32 len,u32 dbg_path)6720 rtw_hal_mac_get_buffer_data(struct rtw_hal_com_t *hal_com, u32 strt_addr,
6721 u8 *buf, u32 len, u32 dbg_path)
6722 {
6723 struct hal_info_t *hal_info = hal_com->hal_priv;
6724 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6725
6726 mac_mem_dump(mac, MAC_AX_MEM_SHARED_BUF, strt_addr, buf, len, dbg_path);
6727 }
6728
6729 void
rtl_hal_dump_sec_cam_tbl(struct rtw_hal_com_t * hal_com)6730 rtl_hal_dump_sec_cam_tbl(struct rtw_hal_com_t *hal_com)
6731 {
6732 u32 i = 0;
6733 u32 sec_cam_tbl_sz = 128;
6734 struct hal_info_t *hal = hal_com->hal_priv;
6735 struct mac_ax_adapter *mac = hal_to_mac(hal);
6736 struct sec_cam_table_t *sec_cam_table = mac->hw_info->sec_cam_table;
6737 struct sec_cam_entry_t *entry = NULL;
6738
6739 PHL_PRINT("===== HW Info Security CAM Table =====\n");
6740 PHL_PRINT("entry valid mac_id key_id key_type\n");
6741 for (i = 0; i < sec_cam_tbl_sz; i++) {
6742 entry = sec_cam_table->sec_cam_entry[i];
6743 if (entry == NULL)
6744 continue;
6745
6746 PHL_PRINT(" %3d %3d %3d %3d %3d\n",
6747 i, entry->valid, entry->mac_id, entry->key_id, entry->key_type);
6748 }
6749 }
6750
halmac_cmd_parser(struct hal_info_t * hal_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)6751 void halmac_cmd_parser(struct hal_info_t *hal_info, char input[][MAX_ARGV],
6752 u32 input_num, char *output, u32 out_len)
6753 {
6754 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6755
6756 mac->ops->halmac_cmd_parser(mac, input, input_num, output, out_len);
6757 }
6758
6759
halmac_cmd(struct hal_info_t * hal_info,char * input,char * output,u32 out_len)6760 s32 halmac_cmd(struct hal_info_t *hal_info, char *input, char *output, u32 out_len)
6761 {
6762 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6763
6764 return mac->ops->halmac_cmd(mac, input, output, out_len);
6765 }
6766
rtw_hal_mac_proc_cmd(struct hal_info_t * hal_info,struct rtw_proc_cmd * incmd,char * output,u32 out_len)6767 bool rtw_hal_mac_proc_cmd(struct hal_info_t *hal_info, struct rtw_proc_cmd *incmd,
6768 char *output, u32 out_len)
6769 {
6770 if(incmd->in_type == RTW_ARG_TYPE_BUF)
6771 halmac_cmd(hal_info, incmd->in.buf, output, out_len);
6772 else if(incmd->in_type == RTW_ARG_TYPE_ARRAY){
6773 halmac_cmd_parser(hal_info, incmd->in.vector,
6774 incmd->in_cnt_len, output, out_len);
6775 }
6776
6777 return true;
6778 }
6779
_ac_drv2mac(u8 ac,u8 wmm)6780 static enum mac_ax_cmac_path_sel _ac_drv2mac(u8 ac, u8 wmm)
6781 {
6782 enum mac_ax_cmac_path_sel sel = MAC_AX_CMAC_PATH_SEL_INVALID;
6783
6784
6785 switch (ac) {
6786 case 0:
6787 /* BE */
6788 sel = MAC_AX_CMAC_PATH_SEL_BE0;
6789 break;
6790 case 1:
6791 /* BK */
6792 sel = MAC_AX_CMAC_PATH_SEL_BK0;
6793 break;
6794 case 2:
6795 /* VI */
6796 sel = MAC_AX_CMAC_PATH_SEL_VI0;
6797 break;
6798 case 3:
6799 /* VO */
6800 sel = MAC_AX_CMAC_PATH_SEL_VO0;
6801 break;
6802 }
6803
6804 if (sel != MAC_AX_CMAC_PATH_SEL_INVALID && wmm)
6805 /* wmm == 1 */
6806 sel += 4;
6807
6808 return sel;
6809 }
6810
6811 /**
6812 * rtw_hal_mac_set_edca() - setup WMM EDCA parameter
6813 * @hal_com: struct rtw_hal_com_t *
6814 * @band: 0x0: band0, 0x1: band1
6815 * @wmm: hardware wmm index
6816 * @ac: Access Category, 0:BE, 1:BK, 2:VI, 3:VO
6817 * @param: AIFS:BIT[7:0], CWMIN:BIT[11:8], CWMAX:BIT[15:12],
6818 * TXOP:BIT[31:16]
6819 *
6820 * Setup WMM EDCA parameter set for specific AC.
6821 *
6822 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
6823 */
6824 enum rtw_hal_status
rtw_hal_mac_set_edca(struct rtw_hal_com_t * hal_com,u8 band,u8 wmm,u8 ac,u32 param)6825 rtw_hal_mac_set_edca(struct rtw_hal_com_t *hal_com, u8 band, u8 wmm, u8 ac,
6826 u32 param)
6827 {
6828 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
6829 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6830 struct mac_ax_edca_param edca = {0};
6831 u32 err = 0;
6832
6833
6834 edca.band = band;
6835 edca.path = _ac_drv2mac(ac, wmm);
6836 edca.txop_32us = param >> 16;
6837 edca.ecw_max = (param >> 12) & 0xF;
6838 edca.ecw_min = (param >> 8) & 0xF;
6839 edca.aifs_us = param & 0xFF;
6840
6841 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_EDCA_PARAM, &edca);
6842 if (err)
6843 return RTW_HAL_STATUS_FAILURE;
6844
6845 return RTW_HAL_STATUS_SUCCESS;
6846 }
6847
6848 #ifdef CONFIG_PHL_TWT
6849 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)6850 rtw_hal_mac_twt_info_update(void *hal, struct rtw_phl_twt_info twt_info, struct rtw_wifi_role_t *role, u8 action)
6851 {
6852 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
6853 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6854 struct mac_ax_twt_para mac_twt_para = {0};
6855 u32 mac_status = MACSUCCESS;
6856
6857 switch (twt_info.nego_type)
6858 {
6859 case RTW_PHL_INDIV_TWT:
6860 mac_twt_para.nego_tp = MAC_AX_TWT_NEGO_TP_IND;
6861 mac_twt_para.flow_id = 0;
6862 break;
6863 case RTW_PHL_WAKE_TBTT_INR:
6864 mac_twt_para.nego_tp = MAC_AX_TWT_NEGO_TP_WAKE;
6865 mac_twt_para.flow_id = 0;
6866 break;
6867 case RTW_PHL_BCAST_TWT:
6868 mac_twt_para.nego_tp = MAC_AX_TWT_NEGO_TP_BRC;
6869 mac_twt_para.flow_id = twt_info.bcast_twt_id;
6870 break;
6871 default:
6872 PHL_ERR("%s : Error TWT nego type %d\n", __func__, twt_info.nego_type);
6873 return RTW_HAL_STATUS_FAILURE;
6874 }
6875 switch (action) {
6876 case TWT_CFG_ADD:
6877 mac_twt_para.act = MAC_AX_TWT_ACT_TP_ADD;
6878 break;
6879 case TWT_CFG_DELETE:
6880 mac_twt_para.act = MAC_AX_TWT_ACT_TP_DEL;
6881 break;
6882 case TWT_CFG_MODIFY:
6883 mac_twt_para.act = MAC_AX_TWT_ACT_TP_MOD;
6884 break;
6885 default:
6886 PHL_ERR("%s : Error TWT action %d\n", __func__, action);
6887 return RTW_HAL_STATUS_FAILURE;
6888 }
6889 mac_twt_para.trig = twt_info.trigger;
6890 mac_twt_para.flow_tp = twt_info.flow_type;
6891 mac_twt_para.proct = twt_info.twt_protection;
6892 mac_twt_para.id = twt_info.twt_id;
6893 mac_twt_para.wake_exp = twt_info.twt_wake_int_exp;
6894 mac_twt_para.band = role->hw_band;
6895 mac_twt_para.port = role->hw_port;
6896 mac_twt_para.rsp_pm = twt_info.responder_pm_mode;
6897 mac_twt_para.wake_unit = twt_info.wake_dur_unit;
6898 mac_twt_para.impt = twt_info.implicit_lastbcast;
6899 mac_twt_para.wake_man = twt_info.twt_wake_int_mantissa;
6900 mac_twt_para.dur = twt_info.nom_min_twt_wake_dur;
6901 mac_twt_para.trgt_l = twt_info.target_wake_time_l;
6902 mac_twt_para.trgt_h = twt_info.target_wake_time_h;
6903 /* HalMac API to setup/delete TWT config*/
6904 mac_status = mac->ops->twt_info_upd_h2c(mac, &mac_twt_para);
6905 if (MACSUCCESS != mac_status){
6906 PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_hal_mac_twt_info_update(): mac_twt_info_upd_h2c fail(%d)\n",
6907 mac_status);
6908 return RTW_HAL_STATUS_FAILURE;
6909 }
6910 return RTW_HAL_STATUS_SUCCESS;
6911 }
6912
6913 enum rtw_hal_status
rtw_hal_mac_twt_sta_update(void * hal,u8 macid,u8 twt_id,u8 action)6914 rtw_hal_mac_twt_sta_update(void *hal, u8 macid, u8 twt_id, u8 action)
6915 {
6916 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
6917 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6918 struct mac_ax_twtact_para mac_twtact_para = {0};
6919 u32 mac_status = MACSUCCESS;
6920
6921 switch (action) {
6922 case TWT_STA_ADD_MACID:
6923 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_ADD;
6924 break;
6925 case TWT_STA_DEL_MACID:
6926 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_DEL;
6927 break;
6928 case TWT_STA_TETMINATW_SP:
6929 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_TRMNT;
6930 break;
6931 case TWT_STA_SUSPEND_TWT:
6932 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_SUS;
6933 break;
6934 case TWT_STA_RESUME_TWT:
6935 mac_twtact_para.act = MAC_AX_TWTACT_ACT_TP_RSUM;
6936 break;
6937 default:
6938 PHL_ERR("%s : Error TWT action %d\n", __func__, action);
6939 return RTW_HAL_STATUS_FAILURE;
6940 }
6941 mac_twtact_para.macid = macid;
6942 mac_twtact_para.id = twt_id;
6943 /* Call HalMac API to setup/delete TWT STA config*/
6944 mac_status = mac->ops->twt_act_h2c(mac, &mac_twtact_para);
6945 if (MACSUCCESS != mac_status) {
6946 PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_hal_mac_twt_sta_update(): mac_twt_act_h2c fail(%d)\n",
6947 mac_status);
6948 return RTW_HAL_STATUS_FAILURE;
6949 }
6950 return RTW_HAL_STATUS_SUCCESS;
6951 }
6952
6953 enum rtw_hal_status
rtw_hal_mac_twt_sta_announce(void * hal,u8 macid)6954 rtw_hal_mac_twt_sta_announce(void *hal, u8 macid)
6955 {
6956 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
6957 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6958 struct mac_ax_twtanno_para mac_twtanno_para = {0};
6959 u32 mac_status = MACSUCCESS;
6960
6961 mac_twtanno_para.macid = macid;
6962 mac_status = mac->ops->twt_anno_h2c(mac, &mac_twtanno_para);
6963 if (MACSUCCESS != mac_status) {
6964 PHL_TRACE(COMP_PHL_TWT, _PHL_DEBUG_, "rtw_hal_mac_twt_sta_announce(): mac_twt_anno_h2c fail(%d)\n",
6965 mac_status);
6966 return RTW_HAL_STATUS_FAILURE;
6967 }
6968 return RTW_HAL_STATUS_SUCCESS;
6969 }
6970 #endif /* CONFIG_PHL_TWT */
6971
6972 /**
6973 * rtw_hal_mac_get_ampdu_cfg() - get ampdu config
6974 * @hal_com: struct rtw_hal_com_t *
6975 * @band: 0x0: band0, 0x1: band1
6976 * @cfg: struct hal_ax_ampdu_cfg *
6977 * Get ampdu config.
6978 * Return RTW_HAL_STATUS_SUCCESS when query is done.
6979 */
6980 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)6981 rtw_hal_mac_get_ampdu_cfg(struct rtw_hal_com_t *hal_com,
6982 u8 band,
6983 struct mac_ax_ampdu_cfg *cfg)
6984 {
6985 /* To Do: need to refine after Mac api updating*/
6986 #if 0
6987 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
6988 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
6989
6990 u32 err = 0;
6991 cfg->band = band;
6992 err = mac->ops->get_hw_value(mac, MAC_AX_HW_GET_AMPDU_CFG, cfg);
6993 if (err)
6994 return RTW_HAL_STATUS_FAILURE;
6995 #endif
6996 return RTW_HAL_STATUS_SUCCESS;
6997 }
6998
6999 /*
7000 * rtw_hal_mac_set_rty_lmt() - setup retry limit parameter
7001 * @hal_com: struct rtw_hal_com_t *
7002 * @macid:
7003 *
7004 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
7005 */
7006 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)7007 rtw_hal_mac_set_rty_lmt(struct rtw_hal_com_t *hal_com, u8 macid,
7008 u8 rts_lmt_sel, u8 rts_lmt_val, u8 data_lmt_sel, u8 data_lmt_val)
7009 {
7010 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
7011 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7012 struct mac_ax_cctl_rty_lmt_cfg cfg = {0};
7013 u32 err = 0;
7014
7015
7016 cfg.macid = macid;
7017 cfg.data_lmt_sel = data_lmt_sel;
7018 cfg.data_lmt_val = data_lmt_val;
7019 cfg.rts_lmt_sel = rts_lmt_sel;
7020 cfg.rts_lmt_val = rts_lmt_val;
7021
7022 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_CCTL_RTY_LMT, &cfg);
7023 if (err)
7024 return RTW_HAL_STATUS_FAILURE;
7025
7026 return RTW_HAL_STATUS_SUCCESS;
7027 }
7028
7029 /**
7030 * rtw_hal_mac_is_tx_mgnt_empty() - Get tx mgnt queue status
7031 * @hal_info: struct rtw_hal_info_t *
7032 * @band: 0x0: band0, 0x1: band1
7033 * @st: queue status, 1 for empty and 0 for not empty.
7034 *
7035 * Return RTW_HAL_STATUS_SUCCESS when setting is ok.
7036 */
7037 enum rtw_hal_status
rtw_hal_mac_is_tx_mgnt_empty(struct hal_info_t * hal_info,u8 band,u8 * st)7038 rtw_hal_mac_is_tx_mgnt_empty(struct hal_info_t *hal_info, u8 band, u8 *st)
7039 {
7040 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7041 struct mac_ax_tx_queue_empty q_st = {{0}};
7042 u32 err;
7043
7044
7045 err = mac->ops->is_txq_empty(mac, &q_st);
7046 if (err != MACSUCCESS)
7047 return RTW_HAL_STATUS_FAILURE;
7048
7049 if ((band == 0) && (q_st.band0_mgnt_empty == DLE_QUEUE_EMPTY))
7050 *st = 1;
7051 else if ((band == 1) && (q_st.band1_mgnt_empty == DLE_QUEUE_EMPTY))
7052 *st = 1;
7053 else
7054 *st = 0;
7055
7056 return RTW_HAL_STATUS_SUCCESS;
7057 }
7058
7059
7060 /* FW Sounding Command */
7061 /* 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)7062 void _hal_max_ax_snd_cmd_ndpa(struct mac_ax_ndpa_para *mac_ndpa,
7063 struct hal_ndpa_para *hal_ndpa,
7064 bool he, u8 sta_nr)
7065 {
7066 u8 i = 0;
7067 struct hal_he_ndpa_sta_info *hal_he_sta = NULL;
7068 struct hal_vht_ndpa_sta_info *hal_vht_sta = NULL;
7069
7070 mac_ndpa->common.frame_ctl = hal_ndpa->common.frame_ctl;
7071 mac_ndpa->common.duration = hal_ndpa->common.duration;
7072 for (i = 0; i < MAC_ALEN; i++) {
7073 mac_ndpa->common.addr1[i] = hal_ndpa->common.addr1[i];
7074 mac_ndpa->common.addr2[i] = hal_ndpa->common.addr2[i];
7075 }
7076 mac_ndpa->snd_dialog.dialog = hal_ndpa->snd_dialog.token;
7077 mac_ndpa->snd_dialog.he = hal_ndpa->snd_dialog.he;
7078 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "halmac he 0x%x sta_nr %d \n", he, sta_nr);
7079 if (he) {
7080 for (i = 0; (i < sta_nr)&&(i < HAL_MAX_HE_SND_STA_NUM); i++) {
7081 hal_he_sta = (struct hal_he_ndpa_sta_info *)
7082 &hal_ndpa->ndpa_sta_info[i];
7083 mac_ndpa->he_para.sta_info[i].aid = hal_he_sta->aid;
7084 mac_ndpa->he_para.sta_info[i].bw = hal_he_sta->bw;
7085 mac_ndpa->he_para.sta_info[i].fb_ng = hal_he_sta->fb_ng;
7086 mac_ndpa->he_para.sta_info[i].disambiguation = 1;
7087 mac_ndpa->he_para.sta_info[i].cb = hal_he_sta->cb;//cb nc
7088 mac_ndpa->he_para.sta_info[i].nc = hal_he_sta->nc;//cb nc
7089 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",
7090 i, mac_ndpa->he_para.sta_info[i].aid,
7091 mac_ndpa->he_para.sta_info[i].bw,
7092 mac_ndpa->he_para.sta_info[i].fb_ng,
7093 mac_ndpa->he_para.sta_info[i].cb,
7094 mac_ndpa->he_para.sta_info[i].nc);
7095 }
7096 } else {
7097 for (i = 0; (i < sta_nr)&&(i < HAL_MAX_VHT_SND_STA_NUM); i++) {
7098 hal_vht_sta = (struct hal_vht_ndpa_sta_info *)
7099 &hal_ndpa->ndpa_sta_info[i];
7100 mac_ndpa->vht_para.sta_info[i].aid =
7101 (u16)hal_vht_sta->aid12;
7102 mac_ndpa->vht_para.sta_info[i].fb_type =
7103 (u16)hal_vht_sta->feedback_type;
7104 mac_ndpa->vht_para.sta_info[i].nc =
7105 (u16)hal_vht_sta->nc;
7106 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "halmac cmd buf VHT(%d) : aid 0x%x fb 0x%x nc 0x%x\n",
7107 i,
7108 mac_ndpa->vht_para.sta_info[i].aid,
7109 mac_ndpa->vht_para.sta_info[i].fb_type,
7110 mac_ndpa->vht_para.sta_info[i].nc);
7111 }
7112 }
7113 }
7114 /* 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)7115 void _hal_max_ax_snd_cmd_bfrp_vht(struct mac_ax_bfrp_para *mac_bfrp,
7116 struct hal_bfrp_para *hal_bfrp, u8 bfrp_num)
7117 {
7118 struct mac_ax_vht_bfrp_para *mac_vht_bfrp = NULL;
7119 struct hal_bfrp_vht *hal_vht_bfrp = NULL;
7120 u8 i = 0, j = 0;
7121 for (i = 0; (i <= bfrp_num)&&(i < HAL_MAX_VHT_BFRP_NUM); i++){
7122 mac_bfrp->hdr[i].frame_ctl = hal_bfrp->hdr[i].frame_ctl;
7123 mac_bfrp->hdr[i].duration = hal_bfrp->hdr[i].duration;
7124 for (j = 0; j < MAC_ALEN; j++) {
7125 mac_bfrp->hdr[i].addr1[j] = hal_bfrp->hdr[i].addr1[j];
7126 mac_bfrp->hdr[i].addr2[j] = hal_bfrp->hdr[i].addr2[j];
7127 }
7128 mac_vht_bfrp = &mac_bfrp->vht_para[i];
7129 hal_vht_bfrp = &hal_bfrp->vht_para[i];
7130 mac_vht_bfrp->retransmission_bitmap = hal_vht_bfrp->rexmit_bmp;
7131 }
7132 }
7133 /* 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)7134 void _hal_max_ax_snd_cmd_bfrp_he(struct mac_ax_bfrp_para *mac_bfrp,
7135 struct hal_bfrp_para *hal_bfrp,
7136 u8 num_1, u8 num_2)
7137 {
7138 u8 i = 0;
7139 struct mac_ax_he_bfrp_para *mac_he_bfrp = NULL;
7140 struct hal_bfrp_he *hal_he_bfrp = NULL;
7141
7142 /* BFRP-0 */
7143 if (num_1) {
7144 mac_bfrp->hdr[0].frame_ctl = hal_bfrp->hdr[0].frame_ctl;
7145 mac_bfrp->hdr[0].duration = hal_bfrp->hdr[0].duration;
7146 for (i = 0; i < MAC_ALEN; i++) {
7147 mac_bfrp->hdr[0].addr1[i] = hal_bfrp->hdr[0].addr1[i];
7148 mac_bfrp->hdr[0].addr2[i] = hal_bfrp->hdr[0].addr2[i];
7149 }
7150 mac_he_bfrp = &mac_bfrp->he_para[0];
7151 hal_he_bfrp = &hal_bfrp->he_para[0];
7152 mac_he_bfrp->common.tgr_info = hal_he_bfrp->common.tgr_info;
7153 mac_he_bfrp->common.ul_len = hal_he_bfrp->common.ul_len;
7154 mac_he_bfrp->common.more_tf = hal_he_bfrp->common.more_tf;
7155 mac_he_bfrp->common.cs_rqd = hal_he_bfrp->common.cs_rqd;
7156 mac_he_bfrp->common.ul_bw = hal_he_bfrp->common.ul_bw;
7157 mac_he_bfrp->common.gi_ltf = hal_he_bfrp->common.gi_ltf;
7158 mac_he_bfrp->common.mimo_ltfmode =
7159 hal_he_bfrp->common.mimo_ltfmode;
7160 mac_he_bfrp->common.num_heltf = hal_he_bfrp->common.num_heltf;
7161 mac_he_bfrp->common.ul_pktext = hal_he_bfrp->common.ul_pktext;
7162 mac_he_bfrp->common.ul_stbc = hal_he_bfrp->common.ul_stbc;
7163 mac_he_bfrp->common.ldpc_extra_sym =
7164 hal_he_bfrp->common.ldpc_extra_sym;
7165 mac_he_bfrp->common.dplr = hal_he_bfrp->common.dplr;
7166 mac_he_bfrp->common.ap_tx_pwr = hal_he_bfrp->common.ap_tx_pwr;
7167 mac_he_bfrp->common.ul_sr = hal_he_bfrp->common.ul_sr;
7168 mac_he_bfrp->common.ul_siga2_rsvd =
7169 hal_he_bfrp->common.ul_siga2_rsvd;
7170 for( i = 0; (i < num_1)&&(i < HAL_MAX_HE_BFRP_STA_NUM); i++) {
7171 mac_he_bfrp->user[i].aid12 =
7172 hal_he_bfrp->user[i].aid12;
7173 mac_he_bfrp->user[i].fbseg_rexmit_bmp =
7174 hal_he_bfrp->fbseg_rexmit_bmp[i];
7175 mac_he_bfrp->user[i].ru_pos =
7176 hal_he_bfrp->user[i].ru_pos;
7177 mac_he_bfrp->user[i].ss_alloc =
7178 hal_he_bfrp->user[i].ss_alloc;
7179 mac_he_bfrp->user[i].ul_dcm =
7180 hal_he_bfrp->user[i].ul_dcm;
7181 mac_he_bfrp->user[i].ul_fec_code =
7182 hal_he_bfrp->user[i].ul_fec_code;
7183 mac_he_bfrp->user[i].ul_mcs =
7184 hal_he_bfrp->user[i].ul_mcs;
7185 mac_he_bfrp->user[i].ul_tgt_rssi =
7186 hal_he_bfrp->user[i].ul_tgt_rssi;
7187 }
7188 }
7189 /* BFRP - 1 */
7190 if (num_2) {
7191 mac_bfrp->hdr[1].frame_ctl = hal_bfrp->hdr[1].frame_ctl;
7192 mac_bfrp->hdr[1].duration = hal_bfrp->hdr[1].duration;
7193 for (i = 0; i < MAC_ALEN; i++) {
7194 mac_bfrp->hdr[1].addr1[i] = hal_bfrp->hdr[1].addr1[i];
7195 mac_bfrp->hdr[1].addr2[i] = hal_bfrp->hdr[1].addr2[i];
7196 }
7197 mac_he_bfrp = &mac_bfrp->he_para[1];
7198 hal_he_bfrp = &hal_bfrp->he_para[1];
7199 mac_he_bfrp->common.tgr_info = hal_he_bfrp->common.tgr_info;
7200 mac_he_bfrp->common.ul_len = hal_he_bfrp->common.ul_len;
7201 mac_he_bfrp->common.more_tf = hal_he_bfrp->common.more_tf;
7202 mac_he_bfrp->common.cs_rqd = hal_he_bfrp->common.cs_rqd;
7203 mac_he_bfrp->common.ul_bw = hal_he_bfrp->common.ul_bw;
7204 mac_he_bfrp->common.gi_ltf = hal_he_bfrp->common.gi_ltf;
7205 mac_he_bfrp->common.mimo_ltfmode =
7206 hal_he_bfrp->common.mimo_ltfmode;
7207 mac_he_bfrp->common.num_heltf = hal_he_bfrp->common.num_heltf;
7208 mac_he_bfrp->common.ul_pktext = hal_he_bfrp->common.ul_pktext;
7209 mac_he_bfrp->common.ul_stbc = hal_he_bfrp->common.ul_stbc;
7210 mac_he_bfrp->common.ldpc_extra_sym =
7211 hal_he_bfrp->common.ldpc_extra_sym;
7212 mac_he_bfrp->common.dplr = hal_he_bfrp->common.dplr;
7213 mac_he_bfrp->common.ap_tx_pwr = hal_he_bfrp->common.ap_tx_pwr;
7214 mac_he_bfrp->common.ul_sr = hal_he_bfrp->common.ul_sr;
7215 mac_he_bfrp->common.ul_siga2_rsvd =
7216 hal_he_bfrp->common.ul_siga2_rsvd;
7217 for( i = 0; (i < num_1)&&(i < HAL_MAX_HE_BFRP_STA_NUM); i++) {
7218 mac_he_bfrp->user[i].aid12 =
7219 hal_he_bfrp->user[i].aid12;
7220 mac_he_bfrp->user[i].fbseg_rexmit_bmp =
7221 hal_he_bfrp->fbseg_rexmit_bmp[i];
7222 mac_he_bfrp->user[i].ru_pos =
7223 hal_he_bfrp->user[i].ru_pos;
7224 mac_he_bfrp->user[i].ss_alloc =
7225 hal_he_bfrp->user[i].ss_alloc;
7226 mac_he_bfrp->user[i].ul_dcm =
7227 hal_he_bfrp->user[i].ul_dcm;
7228 mac_he_bfrp->user[i].ul_fec_code =
7229 hal_he_bfrp->user[i].ul_fec_code;
7230 mac_he_bfrp->user[i].ul_mcs =
7231 hal_he_bfrp->user[i].ul_mcs;
7232 mac_he_bfrp->user[i].ul_tgt_rssi =
7233 hal_he_bfrp->user[i].ul_tgt_rssi;
7234 }
7235 }
7236 }
7237
7238 /* 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)7239 void _hal_max_ax_snd_cmd_bfrp_he_f2p(struct mac_ax_snd_f2P *mac_bfrp_f2p,
7240 struct hal_bfrp_para *hal_bfrp,
7241 u8 num_1, u8 num_2)
7242 {
7243 struct hal_bfrp_he *hal_he_bfrp = NULL;
7244 if (num_1) {
7245 hal_he_bfrp = &hal_bfrp->he_para[0];
7246 mac_bfrp_f2p[0].csi_len_bfrp =
7247 hal_he_bfrp->f2p_info.csi_len_bfrp;
7248 mac_bfrp_f2p[0].tb_t_pe_bfrp =
7249 hal_he_bfrp->f2p_info.tb_t_pe_bfrp;
7250 mac_bfrp_f2p[0].tri_pad_bfrp =
7251 hal_he_bfrp->f2p_info.tri_pad_bfrp;
7252 mac_bfrp_f2p[0].ul_cqi_rpt_tri_bfrp =
7253 hal_he_bfrp->f2p_info.ul_cqi_rpt_tri_bfrp;
7254 mac_bfrp_f2p[0].rf_gain_idx_bfrp =
7255 hal_he_bfrp->f2p_info.rf_gain_idx_bfrp;
7256 mac_bfrp_f2p[0].fix_gain_en_bfrp =
7257 hal_he_bfrp->f2p_info.fix_gain_en_bfrp;
7258 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7259 "==> _hal_max_ax_snd_cmd_bfrp_he_f2p[0] \n");
7260 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7261 "mac_bfrp_f2p[0].csi_len_bfrp = 0x%x \n",
7262 mac_bfrp_f2p[0].csi_len_bfrp);
7263 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7264 "mac_bfrp_f2p[0].tb_t_pe_bfrp = 0x%x \n",
7265 mac_bfrp_f2p[0].tb_t_pe_bfrp);
7266 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7267 "mac_bfrp_f2p[0].tri_pad_bfrp = 0x%x \n",
7268 mac_bfrp_f2p[0].tri_pad_bfrp);
7269 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7270 "mac_bfrp_f2p[0].ul_cqi_rpt_tri_bfrp = 0x%x \n",
7271 mac_bfrp_f2p[0].ul_cqi_rpt_tri_bfrp);
7272 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7273 "mac_bfrp_f2p[0].rf_gain_idx_bfrp = 0x%x \n",
7274 mac_bfrp_f2p[0].rf_gain_idx_bfrp);
7275 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7276 "mac_bfrp_f2p[0].fix_gain_en_bfrp = 0x%x \n",
7277 mac_bfrp_f2p[0].fix_gain_en_bfrp);
7278 }
7279 if (num_2) {
7280 hal_he_bfrp = &hal_bfrp->he_para[1];
7281 mac_bfrp_f2p[1].csi_len_bfrp =
7282 hal_he_bfrp->f2p_info.csi_len_bfrp;
7283 mac_bfrp_f2p[1].tb_t_pe_bfrp =
7284 hal_he_bfrp->f2p_info.tb_t_pe_bfrp;
7285 mac_bfrp_f2p[1].tri_pad_bfrp =
7286 hal_he_bfrp->f2p_info.tri_pad_bfrp;
7287 mac_bfrp_f2p[1].ul_cqi_rpt_tri_bfrp =
7288 hal_he_bfrp->f2p_info.ul_cqi_rpt_tri_bfrp;
7289 mac_bfrp_f2p[1].rf_gain_idx_bfrp =
7290 hal_he_bfrp->f2p_info.rf_gain_idx_bfrp;
7291 mac_bfrp_f2p[1].fix_gain_en_bfrp =
7292 hal_he_bfrp->f2p_info.fix_gain_en_bfrp;
7293 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7294 "==> _hal_max_ax_snd_cmd_bfrp_he_f2p[1] \n");
7295 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7296 "mac_bfrp_f2p[1].csi_len_bfrp = 0x%x \n",
7297 mac_bfrp_f2p[1].csi_len_bfrp);
7298 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7299 "mac_bfrp_f2p[1].tb_t_pe_bfrp = 0x%x \n",
7300 mac_bfrp_f2p[1].tb_t_pe_bfrp);
7301 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7302 "mac_bfrp_f2p[1].tri_pad_bfrp = 0x%x \n",
7303 mac_bfrp_f2p[1].tri_pad_bfrp);
7304 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7305 "mac_bfrp_f2p[1].ul_cqi_rpt_tri_bfrp = 0x%x \n",
7306 mac_bfrp_f2p[1].ul_cqi_rpt_tri_bfrp);
7307 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7308 "mac_bfrp_f2p[1].rf_gain_idx_bfrp = 0x%x \n",
7309 mac_bfrp_f2p[1].rf_gain_idx_bfrp);
7310 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_,
7311 "mac_bfrp_f2p[1].fix_gain_en_bfrp = 0x%x \n",
7312 mac_bfrp_f2p[1].fix_gain_en_bfrp);
7313 }
7314 }
7315
7316
7317 /* 3. WD Content */
_hal_max_ax_snd_cmd_wd(struct mac_ax_snd_wd_para * mac_wd,struct hal_snd_wd_para * hal_wd)7318 void _hal_max_ax_snd_cmd_wd(struct mac_ax_snd_wd_para *mac_wd,
7319 struct hal_snd_wd_para *hal_wd)
7320 {
7321 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "==> _hal_max_ax_snd_cmd_wd \n");
7322 mac_wd->txpktsize = hal_wd->txpktsize;
7323 mac_wd->ndpa_duration = hal_wd->ndpa_duration;
7324 mac_wd->datarate = hal_wd->datarate;
7325 mac_wd->macid = hal_wd->macid;
7326 mac_wd->force_txop = hal_wd->force_txop;
7327 mac_wd->data_bw = hal_wd->data_bw;
7328 mac_wd->gi_ltf = hal_wd->gi_ltf;
7329 mac_wd->data_er = hal_wd->data_er;
7330 mac_wd->data_dcm = hal_wd->data_dcm;
7331 mac_wd->data_stbc = hal_wd->data_stbc;
7332 mac_wd->data_ldpc = hal_wd->data_ldpc;
7333 mac_wd->data_bw_er = hal_wd->data_bw_er;
7334 mac_wd->multiport_id = hal_wd->multiport_id;
7335 mac_wd->mbssid = hal_wd->mbssid;
7336
7337 mac_wd->signaling_ta_pkt_sc = hal_wd->signaling_ta_pkt_sc;
7338 mac_wd->sw_define = hal_wd->sw_define;
7339 mac_wd->txpwr_ofset_type = hal_wd->txpwr_ofset_type;
7340 mac_wd->lifetime_sel = hal_wd->lifetime_sel;
7341 mac_wd->stf_mode = hal_wd->stf_mode;
7342 mac_wd->disdatafb = hal_wd->disdatafb;
7343 mac_wd->data_txcnt_lmt_sel = hal_wd->data_txcnt_lmt_sel;
7344 mac_wd->data_txcnt_lmt = hal_wd->data_txcnt_lmt;
7345 mac_wd->sifs_tx = hal_wd->sifs_tx;
7346 mac_wd->snd_pkt_sel = hal_wd->snd_pkt_sel;
7347 mac_wd->ndpa = hal_wd->ndpa;
7348
7349 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->txpktsize = 0x%x \n", mac_wd->txpktsize);
7350 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->ndpa_duration = 0x%x \n", mac_wd->ndpa_duration);
7351 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->datarate = 0x%x \n", mac_wd->datarate);
7352 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "mac_wd->macid = 0x%x \n", mac_wd->macid);
7353 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->force_txop = 0x%x \n", mac_wd->force_txop);
7354 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_bw = 0x%x \n", mac_wd->data_bw);
7355 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->gi_ltf = 0x%x \n", mac_wd->gi_ltf);
7356 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_er = 0x%x \n", mac_wd->data_er);
7357
7358 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_dcm = 0x%x \n", mac_wd->data_dcm);
7359 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_stbc = 0x%x \n", mac_wd->data_stbc);
7360 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_ldpc = 0x%x \n", mac_wd->data_ldpc);
7361 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_bw_er = 0x%x \n", mac_wd->data_bw_er);
7362 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->multiport_id = 0x%x \n", mac_wd->multiport_id);
7363 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->mbssid = 0x%x \n", mac_wd->mbssid);
7364 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->signaling_ta_pkt_sc = 0x%x \n", mac_wd->signaling_ta_pkt_sc);
7365 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->sw_define = 0x%x \n", mac_wd->sw_define);
7366
7367 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->txpwr_ofset_type = 0x%x \n", mac_wd->txpwr_ofset_type);
7368 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->lifetime_sel = 0x%x \n", mac_wd->lifetime_sel);
7369 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->stf_mode = 0x%x \n", mac_wd->stf_mode);
7370 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->disdatafb = 0x%x \n", mac_wd->disdatafb);
7371 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_txcnt_lmt_sel = 0x%x \n", mac_wd->data_txcnt_lmt_sel);
7372 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->data_txcnt_lmt = 0x%x \n", mac_wd->data_txcnt_lmt);
7373 PHL_TRACE(COMP_PHL_SOUND, _PHL_DEBUG_, "mac_wd->sifs_tx = 0x%x \n", mac_wd->sifs_tx);
7374 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "mac_wd->snd_pkt_sel = 0x%x \n", mac_wd->snd_pkt_sel);
7375 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "mac_wd->ndpa = 0x%x \n", mac_wd->ndpa);
7376 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "<== _hal_max_ax_snd_cmd_wd \n");
7377 }
7378
7379
7380 enum rtw_hal_status
hal_mac_ax_send_fw_snd(struct hal_info_t * hal_info,struct hal_ax_fwcmd_snd * hal_cmd)7381 hal_mac_ax_send_fw_snd(struct hal_info_t *hal_info,
7382 struct hal_ax_fwcmd_snd *hal_cmd)
7383 {
7384 enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
7385 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7386 struct mac_ax_fwcmd_snd snd_cmd = {0};
7387 u8 i = 0, he = 0, sta_nr = 0;
7388
7389 /* 1. COMMAND Common */
7390 snd_cmd.frexgtype = hal_cmd->frame_ex_type;
7391 snd_cmd.bfrp0_user_num = hal_cmd->bfrp0_sta_nr;
7392 snd_cmd.bfrp1_user_num = hal_cmd->bfrp1_sta_nr;
7393 for (i = 0; i < HAL_MAX_HE_SND_STA_NUM; i++) {
7394 snd_cmd.macid[i] = (u8)hal_cmd->macid[i];
7395 }
7396
7397 he = (hal_cmd->frame_ex_type >= HAL_FEXG_TYPE_AX_SU) ? 1 : 0;
7398
7399 if (hal_cmd->frame_ex_type == HAL_FEXG_TYPE_AX_SU) {
7400 sta_nr = 1;
7401 } else {
7402 sta_nr = he ? (hal_cmd->bfrp0_sta_nr + hal_cmd->bfrp1_sta_nr) :
7403 (hal_cmd->frame_ex_type - HAL_FEXG_TYPE_AC_SU + 1);
7404 }
7405
7406 /* 2. NDPA Content */
7407 _hal_max_ax_snd_cmd_ndpa(&snd_cmd.pndpa, &hal_cmd->ndpa,
7408 he, sta_nr);
7409 /* 3. BFRP Content */
7410 if (he) {
7411 _hal_max_ax_snd_cmd_bfrp_he(&snd_cmd.pbfrp, &hal_cmd->bfrp,
7412 hal_cmd->bfrp0_sta_nr, hal_cmd->bfrp1_sta_nr);
7413 _hal_max_ax_snd_cmd_bfrp_he_f2p(snd_cmd.f2p, &hal_cmd->bfrp,
7414 hal_cmd->bfrp0_sta_nr, hal_cmd->bfrp1_sta_nr);
7415 } else {
7416 _hal_max_ax_snd_cmd_bfrp_vht(&snd_cmd.pbfrp, &hal_cmd->bfrp,
7417 (sta_nr - 1));
7418 }
7419 /* 4. WD Content */
7420 /* 4-1 NDPA */
7421 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "NDPA WD: \n");
7422 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[0], &hal_cmd->wd[0]);
7423 /* 4-2 NDP */
7424 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "NDP WD: \n");
7425 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[1], &hal_cmd->wd[1]);
7426 /* 4-3 BFRP*/
7427 if (he) {
7428 if (hal_cmd->bfrp0_sta_nr) {
7429 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "HE BFRP-1 WD: \n");
7430 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[2],
7431 &hal_cmd->wd[2]);
7432 }
7433 if (hal_cmd->bfrp1_sta_nr) {
7434 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "HE BFRP-2 WD: \n");
7435 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[3],
7436 &hal_cmd->wd[3]);
7437 }
7438 } else {
7439 for (i = 0; i < (sta_nr - 1)&&(i < HAL_MAX_VHT_BFRP_NUM);
7440 i++) {
7441 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "VHT BFRP %d WD: \n", i);
7442 _hal_max_ax_snd_cmd_wd(&snd_cmd.wd[2 + i],
7443 &hal_cmd->wd[2 + i]);
7444 }
7445 }
7446
7447 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.macid[0] = 0x%x \n", snd_cmd.macid[0]);
7448 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.bfrp0_user_num = 0x%x \n", snd_cmd.bfrp0_user_num);
7449 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.bfrp1_user_num = 0x%x \n", snd_cmd.bfrp1_user_num);
7450 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.mode = 0x%x \n", snd_cmd.mode);
7451 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] snd_cmd.frexgtype = 0x%x \n", snd_cmd.frexgtype);
7452 hstatus = mac->ops->set_snd_para(mac, &snd_cmd);
7453 PHL_TRACE(COMP_PHL_SOUND, _PHL_INFO_, "[fw_snd] hal_mac_ax_send_fw_snd hstatus = 0x%x\n", hstatus);
7454
7455 return hstatus;
7456 }
7457
7458
7459
7460 enum rtw_hal_status
rtw_hal_mac_tx_mode_sel(struct hal_info_t * hal_info,u8 fw_tx,u8 txop_wmm_en_bm)7461 rtw_hal_mac_tx_mode_sel(struct hal_info_t *hal_info, u8 fw_tx, u8 txop_wmm_en_bm)
7462 {
7463 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7464
7465 struct mac_ax_mac_tx_mode_sel mode_sel = {0};
7466
7467 if (fw_tx)
7468 mode_sel.sw_mode_band0_en = 1;
7469 if (txop_wmm_en_bm & BIT(0))
7470 mode_sel.txop_rot_wmm0_en = 1;
7471 if (txop_wmm_en_bm & BIT(1))
7472 mode_sel.txop_rot_wmm1_en = 1;
7473 if (txop_wmm_en_bm & BIT(2))
7474 mode_sel.txop_rot_wmm2_en = 1;
7475 if (txop_wmm_en_bm & BIT(3))
7476 mode_sel.txop_rot_wmm3_en = 1;
7477
7478 mac->ops->tx_mode_sel(mac, &mode_sel);
7479 return RTW_HAL_STATUS_SUCCESS;
7480 }
7481
rtw_hal_mac_process_c2h(void * hal,struct rtw_c2h_info * c2h)7482 u32 rtw_hal_mac_process_c2h(void *hal, struct rtw_c2h_info *c2h)
7483 {
7484 struct hal_info_t *hal_info = (struct hal_info_t *)hal;
7485 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
7486 struct mac_ax_ccxrpt mac_ccx = {0};
7487 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
7488 #ifdef RTW_WKARD_CCX_RPT_LIMIT_CTRL
7489 u32 retry_limit = 32;
7490 #endif
7491 u32 retid = 0;
7492
7493 hal_status = mac->ops->get_c2h_event(mac, c2h, (enum phl_msg_evt_id *)&retid, (u8 *)&mac_ccx);
7494 /*PHL_INFO("%s, hal_status=%d, retid=%d\n", __func__, hal_status, retid);*/
7495
7496 if (hal_status == RTW_HAL_STATUS_SUCCESS && (retid == MSG_EVT_CCX_REPORT_TX_OK || retid == MSG_EVT_CCX_REPORT_TX_FAIL)) {
7497 #if 0
7498 PHL_INFO("%s, mac_ccx.tx_state=%d\n", __func__, mac_ccx.tx_state);
7499 PHL_INFO("%s, mac_ccx.sw_define=%d\n", __func__, mac_ccx.sw_define);
7500 PHL_INFO("%s, mac_ccx.macid=%d\n", __func__, mac_ccx.macid);
7501 PHL_INFO("%s, mac_ccx.pkt_ok_num=%d\n", __func__, mac_ccx.pkt_ok_num);
7502 PHL_INFO("%s, mac_ccx.data_txcnt=%d\n", __func__, mac_ccx.data_txcnt);
7503 #endif
7504
7505 #ifdef RTW_WKARD_CCX_RPT_LIMIT_CTRL
7506 if (hal_info->hal_com->spe_pkt_cnt_lmt)
7507 retry_limit = hal_info->hal_com->spe_pkt_cnt_lmt;
7508
7509 if (retid == MSG_EVT_CCX_REPORT_TX_FAIL && mac_ccx.data_txcnt != retry_limit)
7510 retid = 0;
7511 #endif
7512 }
7513 return retid;
7514 }
7515
7516 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)7517 rtw_hal_mac_f2p_test_cmd(struct hal_info_t *hal_info,
7518 struct mp_mac_ax_f2p_test_para *info,
7519 struct mp_mac_ax_f2p_wd *f2pwd,
7520 struct mp_mac_ax_f2p_tx_cmd *ptxcmd,
7521 u8 *psigb_addr)
7522 {
7523 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7524 u32 ret = RTW_HAL_STATUS_FAILURE;
7525
7526 if (mac->ops->f2p_test_cmd(mac, (void*)info, (void*)f2pwd, (void*)ptxcmd, psigb_addr) == MACSUCCESS)
7527 ret = RTW_HAL_STATUS_SUCCESS;
7528
7529 return ret;
7530 }
7531
7532 enum rtw_hal_status
rtw_hal_mac_write_pwr_ofst_mode(struct rtw_hal_com_t * hal_com,u8 band)7533 rtw_hal_mac_write_pwr_ofst_mode(struct rtw_hal_com_t *hal_com, u8 band)
7534 {
7535
7536 struct hal_info_t *hal_info = hal_com->hal_priv;
7537 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7538 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7539
7540 if (tpu->normal_mode_lock_en)
7541 return RTW_HAL_STATUS_FAILURE;
7542
7543 mac->ops->write_pwr_ofst_mode(mac, band, tpu);
7544
7545 return RTW_HAL_STATUS_SUCCESS;
7546 }
7547
7548 enum rtw_hal_status
rtw_hal_mac_write_pwr_ofst_bw(struct rtw_hal_com_t * hal_com,u8 band)7549 rtw_hal_mac_write_pwr_ofst_bw(struct rtw_hal_com_t *hal_com, u8 band)
7550 {
7551 struct hal_info_t *hal_info = hal_com->hal_priv;
7552 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7553 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7554
7555 if (tpu->normal_mode_lock_en)
7556 return RTW_HAL_STATUS_FAILURE;
7557
7558 mac->ops->write_pwr_ofst_bw(mac, band, tpu);
7559
7560 return RTW_HAL_STATUS_SUCCESS;
7561 }
7562
7563 enum rtw_hal_status
rtw_hal_mac_write_pwr_ref_reg(struct rtw_hal_com_t * hal_com,u8 band)7564 rtw_hal_mac_write_pwr_ref_reg(struct rtw_hal_com_t *hal_com, u8 band)
7565 {
7566 struct hal_info_t *hal_info = hal_com->hal_priv;
7567 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7568 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7569
7570 if (tpu->normal_mode_lock_en)
7571 return RTW_HAL_STATUS_FAILURE;
7572
7573 mac->ops->write_pwr_ref_reg(mac, band, tpu);
7574
7575 return RTW_HAL_STATUS_SUCCESS;
7576 }
7577
7578 enum rtw_hal_status
rtw_hal_mac_write_pwr_limit_en(struct rtw_hal_com_t * hal_com,u8 band)7579 rtw_hal_mac_write_pwr_limit_en(struct rtw_hal_com_t *hal_com, u8 band)
7580 {
7581 struct hal_info_t *hal_info = hal_com->hal_priv;
7582 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7583 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7584
7585 if (tpu->normal_mode_lock_en)
7586 return RTW_HAL_STATUS_FAILURE;
7587
7588 mac->ops->write_pwr_limit_en(mac, band, tpu);
7589
7590 return RTW_HAL_STATUS_SUCCESS;
7591 }
7592
7593 enum rtw_hal_status
rtw_hal_mac_set_pwr_lmt_en_val(struct rtw_hal_com_t * hal_com,u8 band,bool en_val)7594 rtw_hal_mac_set_pwr_lmt_en_val(struct rtw_hal_com_t *hal_com, u8 band, bool en_val)
7595 {
7596 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7597
7598 if (tpu->normal_mode_lock_en)
7599 return RTW_HAL_STATUS_FAILURE;
7600
7601 tpu->pwr_lmt_en = en_val;
7602
7603 return RTW_HAL_STATUS_SUCCESS;
7604 }
7605
7606 bool
rtw_hal_mac_get_pwr_lmt_en_val(struct rtw_hal_com_t * hal_com,u8 band)7607 rtw_hal_mac_get_pwr_lmt_en_val(struct rtw_hal_com_t *hal_com, u8 band)
7608 {
7609
7610 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7611
7612 return tpu->pwr_lmt_en;
7613 }
7614
7615 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)7616 rtw_hal_mac_set_tpu_mode(struct rtw_hal_com_t *hal_com,
7617 enum rtw_tpu_op_mode op_mode_new, u8 band)
7618 {
7619 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7620
7621 if (op_mode_new == TPU_DBG_MODE) {
7622 tpu->op_mode = TPU_DBG_MODE;
7623 tpu->normal_mode_lock_en = true;
7624 } else {
7625 tpu->op_mode = TPU_NORMAL_MODE;
7626 tpu->normal_mode_lock_en = false;
7627 }
7628
7629 return RTW_HAL_STATUS_SUCCESS;
7630 }
7631
7632 enum rtw_hal_status
rtw_hal_mac_write_pwr_limit_rua_reg(struct rtw_hal_com_t * hal_com,u8 band)7633 rtw_hal_mac_write_pwr_limit_rua_reg(struct rtw_hal_com_t *hal_com, u8 band)
7634 {
7635 struct hal_info_t *hal_info = hal_com->hal_priv;
7636 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7637 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7638
7639 if (tpu->normal_mode_lock_en)
7640 return RTW_HAL_STATUS_FAILURE;
7641
7642 mac->ops->write_pwr_limit_rua_reg(mac, band, tpu);
7643
7644 return RTW_HAL_STATUS_SUCCESS;
7645 }
7646
7647 enum rtw_hal_status
rtw_hal_mac_write_pwr_limit_reg(struct rtw_hal_com_t * hal_com,u8 band)7648 rtw_hal_mac_write_pwr_limit_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_imt_info *lmt = &tpu->rtw_tpu_pwr_imt_i;
7654
7655 if (tpu->normal_mode_lock_en)
7656 return RTW_HAL_STATUS_FAILURE;
7657
7658 mac->ops->write_pwr_limit_reg(mac, band, lmt);
7659
7660 return RTW_HAL_STATUS_SUCCESS;
7661 }
7662
7663 enum rtw_hal_status
rtw_hal_mac_write_pwr_by_rate_reg(struct rtw_hal_com_t * hal_com,u8 band)7664 rtw_hal_mac_write_pwr_by_rate_reg(struct rtw_hal_com_t *hal_com, u8 band)
7665 {
7666 struct hal_info_t *hal_info = hal_com->hal_priv;
7667 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7668 struct rtw_tpu_info *tpu = &hal_com->band[band].rtw_tpu_i;
7669 struct rtw_tpu_pwr_by_rate_info *by_rate = &tpu->rtw_tpu_pwr_by_rate_i;
7670
7671 if (tpu->normal_mode_lock_en)
7672 return RTW_HAL_STATUS_FAILURE;
7673
7674 mac->ops->write_pwr_by_rate_reg(mac, band, by_rate);
7675
7676 return RTW_HAL_STATUS_SUCCESS;
7677 }
7678
7679 enum rtw_hal_status
rtw_hal_mac_get_log_efuse_bt_size(struct rtw_hal_com_t * hal_com,u32 * val)7680 rtw_hal_mac_get_log_efuse_bt_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_LOGICAL_EFUSE_SIZE, val) != MACSUCCESS){
7687 PHL_ERR("%s: Get bt efuse size fail!\n", __FUNCTION__);
7688 return RTW_HAL_STATUS_FAILURE;
7689 }
7690 PHL_INFO("%s: BT Efuse log size = %d!\n", __FUNCTION__, *val);
7691
7692 return RTW_HAL_STATUS_SUCCESS;
7693 }
7694
7695 enum rtw_hal_status
rtw_hal_mac_get_efuse_bt_mask_size(struct rtw_hal_com_t * hal_com,u32 * val)7696 rtw_hal_mac_get_efuse_bt_mask_size(struct rtw_hal_com_t *hal_com, u32 *val)
7697 {
7698 struct hal_info_t *hal_info = hal_com->hal_priv;
7699 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7700
7701 if(mac->ops->get_hw_value(mac,
7702 MAC_AX_HW_GET_BT_EFUSE_MASK_SIZE, val) != MACSUCCESS)
7703 return RTW_HAL_STATUS_FAILURE;
7704
7705 PHL_INFO("%s: bt efuse mask size = %d\n", __FUNCTION__, *val);
7706 return RTW_HAL_STATUS_SUCCESS;
7707 }
7708
7709 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)7710 rtw_hal_mac_write_log_efuse_bt_map(struct rtw_hal_com_t *hal_com,
7711 u8 *map,
7712 u32 map_size,
7713 u8 *mask,
7714 u32 mask_size)
7715 {
7716 struct hal_info_t *hal_info = hal_com->hal_priv;
7717 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7718 struct mac_ax_pg_efuse_info info;
7719 enum rtw_hal_status status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
7720 u8 *tmp_map = NULL;
7721 u8 *tmp_mask = NULL;
7722
7723 tmp_map = _os_mem_alloc(hal_com->drv_priv, map_size);
7724 if(tmp_map == NULL) {
7725 PHL_WARN("%s: Allocate pg map buffer fail!\n", __FUNCTION__);
7726 status = RTW_HAL_STATUS_RESOURCE;
7727 goto err_mem_tmp_map;
7728 }
7729
7730 tmp_mask = _os_mem_alloc(hal_com->drv_priv, mask_size);
7731 if(tmp_mask == NULL) {
7732 PHL_WARN("%s: Allocate pg mask buffer fail!\n", __FUNCTION__);
7733 status = RTW_HAL_STATUS_RESOURCE;
7734 goto err_mem_tmp_mask;
7735 }
7736
7737 /* Copy efuse map to tmp_map buffer */
7738 _os_mem_cpy(hal_com->drv_priv, tmp_map, map, map_size);
7739
7740 /* Copy efuse mask to tmp_mask buffer */
7741 _os_mem_cpy(hal_com->drv_priv, tmp_mask, mask, mask_size);
7742
7743
7744 info.efuse_map = tmp_map;
7745 info.efuse_map_size = map_size;
7746 info.efuse_mask = tmp_mask;
7747 info.efuse_mask_size= mask_size;
7748
7749 if (mac->ops->pg_efuse_by_map_bt(mac,
7750 &info,
7751 MAC_AX_EFUSE_R_DRV) != MACSUCCESS) {
7752 PHL_INFO("%s: BT PG Fail!\n", __FUNCTION__);
7753 status = RTW_HAL_STATUS_EFUSE_PG_FAIL;
7754 }
7755 else {
7756 PHL_INFO("%s: BT PG ok!\n", __FUNCTION__);
7757 status = RTW_HAL_STATUS_SUCCESS;
7758 }
7759 _os_mem_free(hal_com->drv_priv, tmp_map, map_size);
7760 _os_mem_free(hal_com->drv_priv, tmp_mask, mask_size);
7761
7762 return status;
7763
7764 err_mem_tmp_mask:
7765 _os_mem_free(hal_com->drv_priv, tmp_mask, mask_size);
7766
7767 err_mem_tmp_map:
7768 _os_mem_free(hal_com->drv_priv, tmp_map, map_size);
7769
7770 return status;
7771 }
7772
7773 enum rtw_hal_status
rtw_hal_mac_read_log_efuse_bt_map(struct rtw_hal_com_t * hal_com,u8 * map)7774 rtw_hal_mac_read_log_efuse_bt_map(struct rtw_hal_com_t *hal_com, u8 *map)
7775 {
7776 struct hal_info_t *hal_info = hal_com->hal_priv;
7777 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7778
7779 if (mac->ops->dump_log_efuse_bt(mac,
7780 MAC_AX_EFUSE_PARSER_MAP,
7781 #ifdef RTW_WKARD_EFUSE_OPERATION
7782 MAC_AX_EFUSE_R_DRV,
7783 #else
7784 MAC_AX_EFUSE_R_AUTO,
7785 #endif
7786 map
7787 ) != MACSUCCESS) {
7788 PHL_INFO("%s: Dump bt logical efuse fail!\n", __FUNCTION__);
7789 return RTW_HAL_STATUS_FAILURE;
7790 }
7791
7792 PHL_INFO("%s: Dump bt logical efuse ok!\n", __FUNCTION__);
7793 return RTW_HAL_STATUS_SUCCESS;
7794 }
7795
7796 enum rtw_hal_status
rtw_hal_mac_get_efuse_bt_avl(struct rtw_hal_com_t * hal_com,u32 * val)7797 rtw_hal_mac_get_efuse_bt_avl(struct rtw_hal_com_t *hal_com, u32 *val)
7798 {
7799 struct hal_info_t *hal_info = hal_com->hal_priv;
7800 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7801
7802 if (mac->ops->get_efuse_avl_size_bt(mac, val) != MACSUCCESS)
7803 return RTW_HAL_STATUS_FAILURE;
7804
7805 PHL_INFO("%s\n", __FUNCTION__);
7806 return RTW_HAL_STATUS_SUCCESS;
7807 }
7808
7809 enum rtw_hal_status
rtw_hal_mac_get_efuse_bt_size(struct rtw_hal_com_t * hal_com,u32 * val)7810 rtw_hal_mac_get_efuse_bt_size(struct rtw_hal_com_t *hal_com, u32 *val)
7811 {
7812 struct hal_info_t *hal_info = hal_com->hal_priv;
7813 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7814
7815 if (mac->ops->get_hw_value(mac,
7816 MAC_AX_HW_GET_BT_EFUSE_SIZE, val) != MACSUCCESS){
7817 PHL_ERR("%s: Get efuse bt size fail!\n", __FUNCTION__);
7818 return RTW_HAL_STATUS_FAILURE;
7819 }
7820 PHL_INFO("%s: Efuse size = %d!\n", __FUNCTION__, *val);
7821
7822 return RTW_HAL_STATUS_SUCCESS;
7823 }
7824
7825 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)7826 rtw_hal_mac_set_mu_edca(struct rtw_hal_com_t *hal_com, u8 band, u8 ac,
7827 u16 timer, u8 cw_min, u8 cw_max, u8 aifs)
7828 {
7829 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
7830 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7831 struct mac_ax_muedca_param edca = {0};
7832 u32 err = 0;
7833
7834 edca.band = band;
7835 edca.ac = ac;
7836 edca.aifs_us = aifs;
7837 edca.ecw_min = cw_min;
7838 edca.ecw_max = cw_max;
7839 edca.muedca_timer_32us = timer;
7840 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_MUEDCA_PARAM, &edca);
7841 if (err)
7842 return RTW_HAL_STATUS_FAILURE;
7843
7844 return RTW_HAL_STATUS_SUCCESS;
7845 }
7846
7847 enum rtw_hal_status
rtw_hal_mac_set_mu_edca_ctrl(struct rtw_hal_com_t * hal_com,u8 band,u8 wmm,u8 set)7848 rtw_hal_mac_set_mu_edca_ctrl(struct rtw_hal_com_t *hal_com,
7849 u8 band, u8 wmm, u8 set)
7850 {
7851 struct hal_info_t *hal_info = (struct hal_info_t *)hal_com->hal_priv;
7852 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7853 struct mac_ax_muedca_cfg cfg = {0};
7854 u32 err = 0;
7855
7856 cfg.band = band;
7857 cfg.wmm_sel = wmm;
7858 cfg.countdown_en = set;
7859 cfg.tb_update_en = set;
7860 err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_MUEDCA_CTRL, &cfg);
7861 if (err)
7862 return RTW_HAL_STATUS_FAILURE;
7863
7864 return RTW_HAL_STATUS_SUCCESS;
7865 }
7866
rtw_hal_mac_led_set_ctrl_mode(struct hal_info_t * hal_info,enum mac_ax_led_mode mode,u8 led_id)7867 enum rtw_hal_status rtw_hal_mac_led_set_ctrl_mode(struct hal_info_t *hal_info,
7868 enum mac_ax_led_mode mode,
7869 u8 led_id)
7870 {
7871 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7872
7873 if (mac->ops->set_led_mode(mac, mode, led_id) != MACSUCCESS)
7874 return RTW_HAL_STATUS_FAILURE;
7875
7876 return RTW_HAL_STATUS_SUCCESS;
7877 }
7878
rtw_hal_mac_led_ctrl(struct hal_info_t * hal_info,u8 high,u8 led_id)7879 enum rtw_hal_status rtw_hal_mac_led_ctrl(struct hal_info_t *hal_info, u8 high,
7880 u8 led_id)
7881 {
7882 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7883
7884 if (mac->ops->led_ctrl(mac, high, led_id) != MACSUCCESS)
7885 return RTW_HAL_STATUS_FAILURE;
7886
7887 return RTW_HAL_STATUS_SUCCESS;
7888 }
7889
rtw_hal_mac_sw_gpio_ctrl(struct hal_info_t * hal_info,u8 high,u8 gpio)7890 enum rtw_hal_status rtw_hal_mac_sw_gpio_ctrl(struct hal_info_t *hal_info, u8 high,
7891 u8 gpio)
7892 {
7893 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7894
7895 if (mac->ops->sw_gpio_ctrl(mac, high, gpio) != MACSUCCESS)
7896 return RTW_HAL_STATUS_FAILURE;
7897
7898 return RTW_HAL_STATUS_SUCCESS;
7899 }
7900
rtw_hal_mac_set_sw_gpio_mode(struct hal_info_t * hal_info,enum rtw_gpio_mode mode,u8 gpio)7901 enum rtw_hal_status rtw_hal_mac_set_sw_gpio_mode(struct hal_info_t *hal_info, enum rtw_gpio_mode mode,
7902 u8 gpio)
7903 {
7904 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7905
7906 if (mac->ops->set_sw_gpio_mode(mac, mode, gpio) != MACSUCCESS)
7907 return RTW_HAL_STATUS_FAILURE;
7908
7909 return RTW_HAL_STATUS_SUCCESS;
7910 }
7911
rtw_hal_mac_get_wl_dis_val(struct hal_info_t * hal_info,u8 * val)7912 enum rtw_hal_status rtw_hal_mac_get_wl_dis_val(struct hal_info_t *hal_info, u8 *val)
7913 {
7914 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7915
7916 if (mac->ops->get_wl_dis_val(mac, val) != MACSUCCESS)
7917 return RTW_HAL_STATUS_FAILURE;
7918
7919 return RTW_HAL_STATUS_SUCCESS;
7920 }
7921
7922 enum rtw_hal_status
rtw_hal_mac_pcie_trx_mit(struct hal_info_t * hal_info,struct mac_ax_pcie_trx_mitigation * mit_info)7923 rtw_hal_mac_pcie_trx_mit(struct hal_info_t *hal_info,
7924 struct mac_ax_pcie_trx_mitigation *mit_info)
7925 {
7926 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7927
7928 if (MACSUCCESS !=
7929 mac->ops->set_hw_value(mac, MAX_AX_HW_PCIE_MIT, mit_info))
7930 return RTW_HAL_STATUS_FAILURE;
7931
7932 return RTW_HAL_STATUS_SUCCESS;
7933 }
7934
7935 enum rtw_hal_status
rtw_hal_mac_read_efuse_bt_hidden(struct rtw_hal_com_t * hal_com,u32 addr,u32 size,u8 * val)7936 rtw_hal_mac_read_efuse_bt_hidden(struct rtw_hal_com_t *hal_com, u32 addr, u32 size, u8 *val)
7937 {
7938 struct hal_info_t *hal_info = hal_com->hal_priv;
7939 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7940
7941 if (mac->ops->read_efuse(mac, addr, size, val, MAC_AX_EFUSE_BANK_BT) != MACSUCCESS)
7942 return RTW_HAL_STATUS_FAILURE;
7943
7944 PHL_INFO("%s\n", __FUNCTION__);
7945 return RTW_HAL_STATUS_SUCCESS;
7946 }
7947
7948 enum rtw_hal_status
rtw_hal_mac_write_efuse_bt_hidden(struct rtw_hal_com_t * hal_com,u32 addr,u8 val)7949 rtw_hal_mac_write_efuse_bt_hidden(struct rtw_hal_com_t *hal_com, u32 addr, u8 val)
7950 {
7951 struct hal_info_t *hal_info = hal_com->hal_priv;
7952 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7953
7954 u8 tmp_value;
7955
7956 if (mac->ops->read_efuse(mac, addr, 1, &tmp_value, MAC_AX_EFUSE_BANK_BT) != MACSUCCESS) {
7957 PHL_INFO("%s read bt efuse hideen block fail.\n", __FUNCTION__);
7958 return RTW_HAL_STATUS_FAILURE;
7959 }
7960
7961 if(tmp_value != 0xFF) {
7962 PHL_INFO("%s bt efuse hidden offset = 0x%x has value = 0x%x.\n", __FUNCTION__, addr, tmp_value);
7963 return RTW_HAL_STATUS_FAILURE;
7964 }
7965
7966 if (mac->ops->write_efuse(mac, addr, val, MAC_AX_EFUSE_BANK_BT) != MACSUCCESS) {
7967 PHL_INFO("%s write bt efuse hideen block fail.\n", __FUNCTION__);
7968 return RTW_HAL_STATUS_FAILURE;
7969 }
7970
7971 PHL_INFO("%s\n", __FUNCTION__);
7972 return RTW_HAL_STATUS_SUCCESS;
7973 }
7974
7975 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)7976 rtw_hal_mac_tsf_sync(struct hal_info_t *hal_info,
7977 u8 from_port, u8 to_port, enum phl_band_idx band,
7978 s32 sync_offset_tu, enum hal_tsf_sync_act action)
7979 {
7980 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
7981 enum mac_ax_tsf_sync_act mac_action = MAC_AX_TSF_SYNC_NOW_ONCE;
7982 s32 sync_offset_unit = 0;/* for halmac API use, unit is 32us */
7983
7984 switch (action){
7985 case HAL_TSF_SYNC_NOW_ONCE :
7986 mac_action = MAC_AX_TSF_SYNC_NOW_ONCE;
7987 break;
7988 case HAL_TSF_EN_SYNC_AUTO :
7989 mac_action = MAC_AX_TSF_EN_SYNC_AUTO;
7990 break;
7991 case HAL_TSF_DIS_SYNC_AUTO :
7992 mac_action = MAC_AX_TSF_DIS_SYNC_AUTO;
7993 break;
7994 default :
7995 PHL_ERR("Unknown tsf sync action %d\n", action);
7996 goto _error;
7997 }
7998
7999 /* covert TU to unit(unit is 32us, 1TU=1024us=32*32us) */
8000 sync_offset_unit = sync_offset_tu * 32;
8001
8002 if (mac->ops->tsf_sync(mac, from_port, to_port,
8003 sync_offset_unit, mac_action) == MACSUCCESS)
8004 return RTW_HAL_STATUS_SUCCESS;
8005 _error:
8006 return RTW_HAL_STATUS_FAILURE;
8007 }
8008
8009 /**
8010 * rtw_hal_mac_get_sec_cam() - get the security cam raw data from HW
8011 * @hal_info: struct hal_info_t *
8012 * @num: How many cam you wnat to dump from the first one.
8013 * @buf: ptr to buffer which store the content from HW.
8014 * If buf is NULL, use console as debug path.
8015 * @size Size of allocated memroy for @buf.
8016 * The size should be @num * size of security cam offset(0x20).
8017 *
8018 * Return RTW_HAL_STATUS_SUCCESS when function successfully works,
8019 * otherwise, return RTW_HAL_STATUS_FAILURE.
8020 */
8021 enum rtw_hal_status
rtw_hal_mac_get_sec_cam(struct hal_info_t * hal_info,u16 num,u8 * buf,u16 size)8022 rtw_hal_mac_get_sec_cam(struct hal_info_t *hal_info, u16 num, u8 *buf, u16 size)
8023 {
8024 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8025 int i = 0;
8026 /* ToDO: fix the magic number later */
8027 u8 sec_cam_offset_sz = 0x20;
8028
8029 if (buf == NULL) {
8030 /* to console */
8031 for (i = 0; i < num; i++) {
8032 PHL_INFO("======= SEC CAM (%d)DUMP =======\n", i);
8033 mac_mem_dump(mac, MAC_AX_MEM_SECURITY_CAM, i*sec_cam_offset_sz\
8034 , NULL, sec_cam_offset_sz, 0);
8035 PHL_INFO("\n");
8036 }
8037 } else {
8038 /* to buffer */
8039 if (size < sec_cam_offset_sz*num) {
8040 PHL_ERR("%s buf size is not enough to dump security cam\n", __func__);
8041 return RTW_HAL_STATUS_FAILURE;
8042 }
8043
8044 for (i = 0; i < num; i++)
8045 mac_mem_dump(mac, MAC_AX_MEM_SECURITY_CAM, i*sec_cam_offset_sz\
8046 , buf + (i*sec_cam_offset_sz), sec_cam_offset_sz, 1);
8047 }
8048 return RTW_HAL_STATUS_SUCCESS;
8049 }
8050
8051 /**
8052 * rtw_hal_mac_get_addr_cam() - get the address cam raw data from HW
8053 * @hal_info: struct hal_info_t *
8054 * @num: How many cam you wnat to dump from the first one.
8055 * @buf: ptr to buffer which store the content from HW.
8056 * If buf is NULL, use console as debug path.
8057 * @size Size of allocated memroy for @buf.
8058 * The size should be @num * size of Addr cam offset(0x40).
8059 *
8060 * Return RTW_HAL_STATUS_SUCCESS when function successfully works,
8061 * otherwise, return RTW_HAL_STATUS_FAILURE.
8062 */
8063 enum rtw_hal_status
rtw_hal_mac_get_addr_cam(struct hal_info_t * hal_info,u16 num,u8 * buf,u16 size)8064 rtw_hal_mac_get_addr_cam(struct hal_info_t *hal_info, u16 num, u8 *buf, u16 size)
8065 {
8066 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8067 int i = 0;
8068 /* ToDO: fix the magic number later */
8069 u8 addr_cam_offset_sz = 0x40;
8070
8071 if (buf == NULL) {
8072 /* to console */
8073 for (i = 0; i < num; i++) {
8074 PHL_INFO("======= ADDR CAM (%d)DUMP =======\n", i);
8075 mac_mem_dump(mac, MAC_AX_MEM_ADDR_CAM, i*addr_cam_offset_sz\
8076 , NULL, addr_cam_offset_sz, 0);
8077 PHL_INFO("\n");
8078 }
8079 } else {
8080 /* to buffer */
8081 if (size < addr_cam_offset_sz*num) {
8082 PHL_ERR("%s buf size is not enough to dump addr cam\n", __func__);
8083 return RTW_HAL_STATUS_FAILURE;
8084 }
8085
8086 for (i = 0; i < num; i++)
8087 mac_mem_dump(mac, MAC_AX_MEM_ADDR_CAM, i*addr_cam_offset_sz\
8088 , buf + (i*addr_cam_offset_sz), addr_cam_offset_sz, 1);
8089
8090 }
8091 return RTW_HAL_STATUS_SUCCESS;
8092 }
8093
rtw_hal_mac_get_tsf(struct hal_info_t * hal,u8 * port,u32 * tsf_h,u32 * tsf_l)8094 enum rtw_hal_status rtw_hal_mac_get_tsf(struct hal_info_t *hal, u8 *port,
8095 u32 *tsf_h, u32 *tsf_l)
8096 {
8097 struct mac_ax_adapter *mac = hal_to_mac(hal);
8098 struct mac_ax_ops *hal_mac_ops = mac->ops;
8099 struct mac_ax_port_tsf val = {0};
8100
8101 val.port = *port;
8102 if (hal_mac_ops->get_hw_value(mac, MAC_AX_HW_GET_TSF, &val))
8103 return RTW_HAL_STATUS_FAILURE;
8104 *tsf_h = val.tsf_h;
8105 *tsf_l = val.tsf_l;
8106 return RTW_HAL_STATUS_SUCCESS;
8107 }
8108
rtw_hal_mac_cfg_txhci(struct hal_info_t * hal,u8 en)8109 enum rtw_hal_status rtw_hal_mac_cfg_txhci(struct hal_info_t *hal, u8 en)
8110 {
8111 struct mac_ax_adapter *mac = hal_to_mac(hal);
8112 struct mac_ax_ops *hal_mac_ops = mac->ops;
8113 enum mac_ax_func_sw mac_en;
8114 u32 ret = 0;
8115
8116 if (en)
8117 mac_en = MAC_AX_FUNC_EN;
8118 else
8119 mac_en = MAC_AX_FUNC_DIS;
8120
8121 ret = hal_mac_ops->intf_ops->ctrl_txhci(mac, mac_en);
8122
8123 return (ret == MACSUCCESS) ?
8124 (RTW_HAL_STATUS_SUCCESS):(RTW_HAL_STATUS_FAILURE);
8125 }
8126
rtw_hal_mac_cfg_rxhci(struct hal_info_t * hal,u8 en)8127 enum rtw_hal_status rtw_hal_mac_cfg_rxhci(struct hal_info_t *hal, u8 en)
8128 {
8129 struct mac_ax_adapter *mac = hal_to_mac(hal);
8130 struct mac_ax_ops *hal_mac_ops = mac->ops;
8131 enum mac_ax_func_sw mac_en;
8132 u32 ret = 0;
8133
8134 if (en)
8135 mac_en = MAC_AX_FUNC_EN;
8136 else
8137 mac_en = MAC_AX_FUNC_DIS;
8138
8139 ret = hal_mac_ops->intf_ops->ctrl_rxhci(mac, mac_en);
8140
8141 return (ret == MACSUCCESS) ?
8142 (RTW_HAL_STATUS_SUCCESS):(RTW_HAL_STATUS_FAILURE);
8143 }
8144
8145 #ifdef CONFIG_MCC_SUPPORT
_hal_mac_mcc_fill_role_info(struct rtw_phl_mcc_role * mcc_role,struct mac_ax_mcc_role * info)8146 void _hal_mac_mcc_fill_role_info(struct rtw_phl_mcc_role *mcc_role,
8147 struct mac_ax_mcc_role *info)
8148 {
8149 struct rtw_phl_mcc_policy_info *policy = &mcc_role->policy;
8150
8151 if (mcc_role->bt_role) {
8152 info->group = mcc_role->group;
8153 info->btc_in_2g = true;
8154 info->duration = policy->dur_info.dur;
8155 } else {
8156 info->macid = mcc_role->macid;
8157 info->central_ch_seg0 = mcc_role->chandef->center_ch;
8158 info->central_ch_seg1 = (u8)mcc_role->chandef->center_freq2;
8159 info->primary_ch = mcc_role->chandef->chan;
8160 info->bandwidth = mcc_role->chandef->bw;
8161 info->group = mcc_role->group;
8162 info->c2h_rpt = policy->c2h_rpt;
8163 info->dis_tx_null = policy->dis_tx_null;
8164 info->dis_sw_retry = policy->dis_sw_retry;
8165 info->in_curr_ch = policy->in_curr_ch;
8166 info->sw_retry_count = policy->sw_retry_count;
8167 info->tx_null_early= policy->tx_null_early;
8168 info->duration = policy->dur_info.dur;
8169 info->courtesy_en = policy->courtesy_en;
8170 info->courtesy_num = policy->courtesy_num;
8171 info->courtesy_target = policy->courtesy_target;
8172 }
8173 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): macid(%d), central_ch_seg0(%d), central_ch_seg1(%d)\n",
8174 info->macid, info->central_ch_seg0, info->central_ch_seg1);
8175 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): primary_ch(%d), bandwidth(%d), group(%d), c2h_rpt(%d)\n",
8176 info->primary_ch, info->bandwidth, info->group, info->c2h_rpt);
8177 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",
8178 info->dis_tx_null, info->dis_sw_retry, info->in_curr_ch);
8179 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",
8180 info->sw_retry_count, info->tx_null_early, info->btc_in_2g);
8181 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): duration(%d)\n",
8182 info->duration);
8183 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "_hal_mac_mcc_fill_role_info(): courtesy_en(%d), courtesy_num(%d), courtesy_target(0x%x)\n",
8184 info->courtesy_en, info->courtesy_num, info->courtesy_target);
8185 }
8186
_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)8187 void _hal_mac_mcc_fill_duration_info(struct rtw_phl_mcc_en_info *en_info,
8188 struct rtw_phl_mcc_bt_info *bt_info,
8189 struct mac_ax_mcc_duration_info *info)
8190 {
8191 info->group = en_info->mcc_role[0].group;
8192 info->btc_in_group = (bt_info->bt_dur > 0) ? 1 : 0;
8193 info->start_macid = en_info->mcc_role[en_info->ref_role_idx].macid;
8194 info->macid_x = en_info->mcc_role[0].macid;
8195 info->macid_y = en_info->mcc_role[1].macid;
8196 info->duration_x = en_info->mcc_role[0].policy.dur_info.dur;
8197 info->duration_y = en_info->mcc_role[1].policy.dur_info.dur;
8198 info->start_tsf_low = en_info->tsf_low;
8199 info->start_tsf_high = en_info->tsf_high;
8200 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",
8201 info->group, info->btc_in_group, info->start_macid,
8202 info->macid_x, info->macid_y);
8203 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",
8204 info->duration_x, info->duration_y, info->start_tsf_high,
8205 info->start_tsf_low);
8206 }
8207
_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)8208 void _hal_mac_mcc_fill_start_info(u8 group, u8 macid, u32 tsf_high, u32 tsf_low,
8209 u8 btc_in_group, u8 old_group_action, u8 old_group,
8210 struct mac_ax_mcc_start *info)
8211 {
8212 info->group = group;
8213 info->btc_in_group = btc_in_group;
8214 info->old_group_action = old_group_action;
8215 info->old_group = old_group;
8216 info->macid = macid;
8217 info->tsf_low = tsf_low;
8218 info->tsf_high = tsf_high;
8219 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",
8220 info->group, info->btc_in_group, info->old_group_action,
8221 info->old_group, info->macid, info->tsf_high, info->tsf_low);
8222 }
8223
rtw_hal_mac_add_mcc(struct hal_info_t * hal,struct rtw_phl_mcc_role * mcc_role)8224 enum rtw_hal_status rtw_hal_mac_add_mcc(struct hal_info_t *hal,
8225 struct rtw_phl_mcc_role *mcc_role)
8226 {
8227 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8228 struct mac_ax_adapter *mac = hal_to_mac(hal);
8229 u32 mac_status;
8230 u16 loop_cnt = 0;
8231 struct mac_ax_mcc_role info = {0};
8232
8233 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_add_mcc()\n");
8234 if (mac == NULL)
8235 goto exit;
8236 _hal_mac_mcc_fill_role_info(mcc_role, &info);
8237 mac_status = mac->ops->add_mcc(mac, &info);
8238 if (mac_status != MACSUCCESS) {
8239 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_add_mcc(): fault, status = %d.\n",
8240 mac_status);
8241 goto exit;
8242 }
8243 do {
8244 if (mac->ops->check_add_mcc_done(mac, (u8)info.group) ==
8245 MACSUCCESS)
8246 break;
8247 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8248 loop_cnt++;
8249 } while (loop_cnt < POLLING_HALMAC_CNT);
8250
8251 if (loop_cnt < POLLING_HALMAC_CNT) {
8252 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_add_mcc(): polling ok, count(%d)\n",
8253 loop_cnt);
8254 hal_status = RTW_HAL_STATUS_SUCCESS;
8255 } else {
8256 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_add_mcc(): polling timeout\n");
8257 }
8258 exit:
8259 return hal_status;
8260 }
8261
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)8262 enum rtw_hal_status rtw_hal_mac_start_mcc(struct hal_info_t *hal,
8263 u8 group, u8 macid, u32 tsf_high, u32 tsf_low,
8264 u8 btc_in_group, u8 old_group_action, u8 old_group)
8265 {
8266 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8267 struct mac_ax_adapter *mac = hal_to_mac(hal);
8268 struct mac_ax_mcc_start info = {0};
8269 u32 mac_status = MACSUCCESS;
8270 u16 loop_cnt = 0;
8271
8272 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",
8273 group, macid, tsf_high, tsf_low, btc_in_group);
8274 if (mac == NULL)
8275 goto exit;
8276 _hal_mac_mcc_fill_start_info(group, macid, tsf_high, tsf_low,
8277 btc_in_group, old_group_action,
8278 old_group, &info);
8279 mac_status = mac->ops->start_mcc(mac, &info);
8280 if (mac_status != MACSUCCESS) {
8281 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_start_mcc(): fault, status = %d.\n",
8282 mac_status);
8283 goto exit;
8284 }
8285 do {
8286 if (mac->ops->check_start_mcc_done(mac, group) ==
8287 MACSUCCESS)
8288 break;
8289 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8290 loop_cnt++;
8291 } while (loop_cnt < POLLING_HALMAC_CNT);
8292
8293 if (loop_cnt < POLLING_HALMAC_CNT) {
8294 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_start_mcc(): polling ok, count(%d)\n",
8295 loop_cnt);
8296 hal_status = RTW_HAL_STATUS_SUCCESS;
8297 } else {
8298 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_start_mcc(): polling timeout\n");
8299 }
8300 exit:
8301 return hal_status;
8302 }
8303
rtw_hal_mac_stop_mcc(struct hal_info_t * hal,u8 group,u8 macid)8304 enum rtw_hal_status rtw_hal_mac_stop_mcc(struct hal_info_t *hal, u8 group,
8305 u8 macid)
8306 {
8307 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8308 struct mac_ax_adapter *mac = hal_to_mac(hal);
8309 u32 mac_status;
8310 u16 loop_cnt = 0;
8311
8312 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_stop_mcc(): group(%d), macid(%d)\n",
8313 group, macid);
8314 if (mac == NULL)
8315 goto exit;
8316 /*prev_groups always set to 1, driver stop all group pattern in the same hw band.*/
8317 mac_status = mac->ops->stop_mcc(mac, group, macid, 1);
8318 if (mac_status != MACSUCCESS) {
8319 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_stop_mcc(): fault, status = %d.\n",
8320 mac_status);
8321 goto exit;
8322 }
8323 do {
8324 if (mac->ops->check_stop_mcc_done(mac, group) ==
8325 MACSUCCESS)
8326 break;
8327 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8328 loop_cnt++;
8329 } while (loop_cnt < POLLING_HALMAC_CNT);
8330
8331 if (loop_cnt < POLLING_HALMAC_CNT) {
8332 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_stop_mcc(): polling ok, count(%d)\n",
8333 loop_cnt);
8334 hal_status = RTW_HAL_STATUS_SUCCESS;
8335 } else {
8336 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_stop_mcc(): polling timeout\n");
8337 }
8338 exit:
8339 return hal_status;
8340 }
8341
rtw_hal_mac_reset_mcc_group(struct hal_info_t * hal,u8 group)8342 enum rtw_hal_status rtw_hal_mac_reset_mcc_group(struct hal_info_t *hal, u8 group)
8343 {
8344 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8345 struct mac_ax_adapter *mac = hal_to_mac(hal);
8346 u32 mac_status;
8347
8348 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> %s(): group(%d)\n",
8349 __func__, group);
8350 if (mac == NULL)
8351 goto exit;
8352
8353 mac_status = mac->ops->reset_mcc_group(mac, group);
8354 if (mac_status != MACSUCCESS) {
8355 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_,
8356 "%s(): reset group(%d) fail, status = %d.\n",
8357 __func__, group, mac_status);
8358 goto exit;
8359 } else {
8360 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_,
8361 "%s(): reset group(%d) ok.\n",
8362 __func__, group);
8363 hal_status = RTW_HAL_STATUS_SUCCESS;
8364 }
8365 exit:
8366 return hal_status;
8367 }
8368
rtw_hal_mac_del_mcc_group(struct hal_info_t * hal,u8 group)8369 enum rtw_hal_status rtw_hal_mac_del_mcc_group(struct hal_info_t *hal, u8 group)
8370 {
8371 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8372 struct mac_ax_adapter *mac = hal_to_mac(hal);
8373 u32 mac_status;
8374 u16 loop_cnt = 0;
8375
8376 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_del_mcc_group(): group(%d)\n",
8377 group);
8378 if (mac == NULL)
8379 goto exit;
8380 /*prev_groups always set to 1, driver stop all group pattern in the same hw band.*/
8381 mac_status = mac->ops->del_mcc_group(mac, group, 1);
8382 if (mac_status != MACSUCCESS) {
8383 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_del_mcc_group(): fault, status = %d.\n",
8384 mac_status);
8385 goto exit;
8386 }
8387
8388 do {
8389 if (mac->ops->check_del_mcc_group_done(mac, group) ==
8390 MACSUCCESS)
8391 break;
8392 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8393 loop_cnt++;
8394 } while (loop_cnt < POLLING_HALMAC_CNT);
8395
8396 if (loop_cnt < POLLING_HALMAC_CNT) {
8397 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_del_mcc_group(): polling ok, count(%d)\n",
8398 loop_cnt);
8399 hal_status = RTW_HAL_STATUS_SUCCESS;
8400 } else {
8401 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_del_mcc_group(): polling timeout\n");
8402 }
8403 exit:
8404 return hal_status;
8405 }
8406
rtw_hal_mac_mcc_request_tsf(struct hal_info_t * hal,u8 group,u8 macid_x,u8 macid_y)8407 enum rtw_hal_status rtw_hal_mac_mcc_request_tsf(struct hal_info_t *hal,
8408 u8 group, u8 macid_x, u8 macid_y)
8409 {
8410 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8411 struct mac_ax_adapter *mac = hal_to_mac(hal);
8412 u32 mac_status;
8413 u16 loop_cnt = 0;
8414
8415 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_mcc_request_tsf(): group(%d), macid_x(%d), macid_y(%d)\n",
8416 group, macid_x, macid_y);
8417 if (mac == NULL)
8418 goto exit;
8419 mac_status = mac->ops->mcc_request_tsf(mac, group, macid_x, macid_y);
8420 if (mac_status != MACSUCCESS) {
8421 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_request_tsf(): fault, status = %d.\n",
8422 mac_status);
8423 goto exit;
8424 }
8425
8426 do {
8427 if (mac->ops->check_mcc_request_tsf_done(mac, group) ==
8428 MACSUCCESS)
8429 break;
8430 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8431 loop_cnt++;
8432 } while (loop_cnt < POLLING_HALMAC_CNT);
8433
8434 if (loop_cnt < POLLING_HALMAC_CNT) {
8435 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_mcc_request_tsf(): polling ok, count(%d)\n",
8436 loop_cnt);
8437 hal_status = RTW_HAL_STATUS_SUCCESS;
8438 } else {
8439 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_request_tsf(): polling timeout\n");
8440 }
8441 exit:
8442 return hal_status;
8443 }
8444
rtw_hal_mac_mcc_macid_bitmap(struct hal_info_t * hal,u8 group,u8 macid,u8 * bitmap,u8 len)8445 enum rtw_hal_status rtw_hal_mac_mcc_macid_bitmap(struct hal_info_t *hal,
8446 u8 group, u8 macid, u8 *bitmap, u8 len)
8447 {
8448 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8449 struct mac_ax_adapter *mac = hal_to_mac(hal);
8450 u32 mac_status;
8451 u16 loop_cnt = 0;
8452
8453 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_mcc_macid_bitmap(): group(%d), macid(%d)\n",
8454 group, macid);
8455 if (mac == NULL)
8456 goto exit;
8457 mac_status = mac->ops->mcc_macid_bitmap(mac, group, macid, bitmap, len);
8458 if (mac_status != MACSUCCESS) {
8459 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_macid_bitmap(): fault, status = %d.\n",
8460 mac_status);
8461 goto exit;
8462 }
8463
8464 do {
8465 if (mac->ops->check_mcc_macid_bitmap_done(mac, group) ==
8466 MACSUCCESS)
8467 break;
8468 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8469 loop_cnt++;
8470 } while (loop_cnt < POLLING_HALMAC_CNT);
8471
8472 if (loop_cnt < POLLING_HALMAC_CNT) {
8473 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_mcc_macid_bitmap(): polling ok, count(%d)\n",
8474 loop_cnt);
8475 hal_status = RTW_HAL_STATUS_SUCCESS;
8476 } else {
8477 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_mcc_macid_bitmap(): polling timeout\n");
8478 }
8479 exit:
8480 return hal_status;
8481 }
8482
rtw_hal_mac_mcc_sync_enable(struct hal_info_t * hal,u8 group,u8 source,u8 target,u8 offset)8483 enum rtw_hal_status rtw_hal_mac_mcc_sync_enable(struct hal_info_t *hal,
8484 u8 group, u8 source, u8 target, u8 offset)
8485 {
8486 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8487 struct mac_ax_adapter *mac = hal_to_mac(hal);
8488 u32 mac_status;
8489 u16 loop_cnt = 0;
8490
8491 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_mcc_sync_enable(): group(%d), source macid(%d), target macid(%d), offset(%d)\n",
8492 group, source, target, offset);
8493 if (mac == NULL)
8494 goto exit;
8495 mac_status = mac->ops->mcc_sync_enable(mac, group, source, target, offset);
8496 if (mac_status != MACSUCCESS) {
8497 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "mac_mcc_sync_enable(): fault, status = %d.\n",
8498 mac_status);
8499 goto exit;
8500 }
8501 do {
8502 if (mac->ops->check_mcc_sync_enable_done(mac, group) ==
8503 MACSUCCESS)
8504 break;
8505 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8506 loop_cnt++;
8507 } while (loop_cnt < POLLING_HALMAC_CNT);
8508
8509 if (loop_cnt < POLLING_HALMAC_CNT) {
8510 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "mac_mcc_sync_enable(): polling ok, count(%d)\n",
8511 loop_cnt);
8512 hal_status = RTW_HAL_STATUS_SUCCESS;
8513 } else {
8514 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "mac_mcc_sync_enable(): polling timeout\n");
8515 }
8516 exit:
8517 return hal_status;
8518 }
8519
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)8520 enum rtw_hal_status rtw_hal_mac_set_duration(struct hal_info_t *hal,
8521 struct rtw_phl_mcc_en_info *en_info,
8522 struct rtw_phl_mcc_bt_info *bt_info)
8523 {
8524 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8525 struct mac_ax_adapter *mac = hal_to_mac(hal);
8526 struct mac_ax_mcc_duration_info info = {0};
8527 u32 mac_status;
8528 u16 loop_cnt = 0;
8529
8530 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, ">>> rtw_hal_mac_set_duration()\n");
8531 _hal_mac_mcc_fill_duration_info(en_info, bt_info, &info);
8532 mac_status = mac->ops->mcc_set_duration(mac, &info);
8533 if (mac_status != MACSUCCESS) {
8534 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_set_duration(): fault, status = %d.\n",
8535 mac_status);
8536 goto exit;
8537 }
8538 do {
8539 if (mac->ops->check_mcc_set_duration_done(mac, (u8)info.group)
8540 == MACSUCCESS)
8541 break;
8542 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8543 loop_cnt++;
8544 } while (loop_cnt < POLLING_HALMAC_CNT);
8545
8546 if (loop_cnt < POLLING_HALMAC_CNT) {
8547 PHL_TRACE(COMP_PHL_MCC, _PHL_INFO_, "rtw_hal_mac_set_duration(): polling ok, count(%d)\n",
8548 loop_cnt);
8549 hal_status = RTW_HAL_STATUS_SUCCESS;
8550 } else {
8551 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_set_duration(): polling timeout\n");
8552 }
8553 exit:
8554 return hal_status;
8555
8556 }
8557
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)8558 enum rtw_hal_status rtw_hal_mac_get_mcc_tsf_rpt(struct hal_info_t *hal,
8559 u8 group, u32 *tsf_x_h, u32 *tsf_x_l,
8560 u32 *tsf_y_h, u32 *tsf_y_l)
8561 {
8562 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8563 struct mac_ax_adapter *mac = hal_to_mac(hal);
8564 u32 mac_status;
8565
8566 if (mac == NULL)
8567 goto exit;
8568 mac_status = mac->ops->get_mcc_tsf_rpt(mac, group, tsf_x_h, tsf_x_l,
8569 tsf_y_h, tsf_y_l);
8570 if (mac_status != MACSUCCESS) {
8571 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_get_mcc_tsf_rpt(): fault, status = %d.\n",
8572 mac_status);
8573 goto exit;
8574 }
8575 hal_status = RTW_HAL_STATUS_SUCCESS;
8576 exit:
8577 return hal_status;
8578 }
8579
rtw_hal_mac_get_mcc_status_rpt(struct hal_info_t * hal,u8 group,u8 * status,u32 * tsf_h,u32 * tsf_l)8580 enum rtw_hal_status rtw_hal_mac_get_mcc_status_rpt(struct hal_info_t *hal,
8581 u8 group, u8 *status, u32 *tsf_h, u32 *tsf_l)
8582 {
8583 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8584 struct mac_ax_adapter *mac = hal_to_mac(hal);
8585 u32 mac_status;
8586
8587 if (mac == NULL)
8588 goto exit;
8589 mac_status = mac->ops->get_mcc_status_rpt(mac, group, status, tsf_h,
8590 tsf_l);
8591 if (mac_status != MACSUCCESS) {
8592 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "mac_mcc_sync_enable(): fault, status = %d.\n",
8593 mac_status);
8594 goto exit;
8595 }
8596 hal_status = RTW_HAL_STATUS_SUCCESS;
8597 exit:
8598 return hal_status;
8599 }
8600
rtw_hal_mac_get_mcc_group(struct hal_info_t * hal,u8 * group)8601 enum rtw_hal_status rtw_hal_mac_get_mcc_group(struct hal_info_t *hal, u8 *group)
8602 {
8603 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
8604 struct mac_ax_adapter *mac = hal_to_mac(hal);
8605 u32 mac_status;
8606
8607 if (mac == NULL)
8608 goto exit;
8609 mac_status = mac->ops->get_mcc_group(mac, group);
8610 if (mac_status != MACSUCCESS) {
8611 PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "rtw_hal_mac_get_mcc_group(): fault, status = %d.\n",
8612 mac_status);
8613 goto exit;
8614 }
8615 hal_status = RTW_HAL_STATUS_SUCCESS;
8616 exit:
8617 return hal_status;
8618 }
8619 #endif /* CONFIG_MCC_SUPPORT */
8620
8621 #ifdef CONFIG_PHL_P2PPS
8622 #define P2P_ACT_INIT 0
8623 #define P2P_ACT_UPDATE 1
8624 #define P2P_ACT_REMOVE 2
8625 #define P2P_ACT_TERMINATE 3
8626
8627 #define P2P_TYPE_GO 0
8628 #define P2P_TYPE_GC 1
8629
_hal_mac_dump_p2p_act_struct(struct mac_ax_p2p_act_info * mac_p2p_info)8630 void _hal_mac_dump_p2p_act_struct(struct mac_ax_p2p_act_info *mac_p2p_info)
8631 {
8632 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): macid = %d\n",
8633 mac_p2p_info->macid);
8634 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): noaid = %d\n",
8635 mac_p2p_info->noaid);
8636 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): act = %d\n",
8637 mac_p2p_info->act);
8638 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): type = %d\n",
8639 mac_p2p_info->type);
8640 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): all_slep = %d\n",
8641 mac_p2p_info->all_slep);
8642 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): srt = %x\n",
8643 mac_p2p_info->srt);
8644 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): itvl = %d\n",
8645 mac_p2p_info->itvl);
8646 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): dur = %d\n",
8647 mac_p2p_info->dur);
8648 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): cnt = %d\n",
8649 mac_p2p_info->cnt);
8650 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_dump_p2p_act_struct(): ctw = %d\n",
8651 mac_p2p_info->ctw);
8652 }
8653
_hal_mac_noa_fill_info(u8 action,struct rtw_phl_noa_desc * desc,u16 macid,struct mac_ax_p2p_act_info * mac_p2p_info)8654 void _hal_mac_noa_fill_info(u8 action,
8655 struct rtw_phl_noa_desc *desc,
8656 u16 macid,
8657 struct mac_ax_p2p_act_info *mac_p2p_info)
8658 {
8659 struct rtw_wifi_role_t *wrole = desc->w_role;
8660
8661 mac_p2p_info->macid = (u8)macid;
8662 mac_p2p_info->noaid = desc->noa_id;
8663 mac_p2p_info->act = action;
8664 if (wrole->type == PHL_RTYPE_AP)
8665 mac_p2p_info->type = P2P_TYPE_GO;
8666 else if (wrole->type == PHL_RTYPE_STATION)
8667 mac_p2p_info->type = P2P_TYPE_GC;
8668 mac_p2p_info->srt = desc->start_t_l;
8669 mac_p2p_info->itvl = desc->interval;
8670 mac_p2p_info->dur = desc->duration;
8671 mac_p2p_info->cnt = desc->count;
8672 }
8673
_hal_mac_get_p2p_stat(struct hal_info_t * hal)8674 enum rtw_hal_status _hal_mac_get_p2p_stat(struct hal_info_t *hal)
8675 {
8676 struct mac_ax_adapter *mac = hal_to_mac(hal);
8677 u16 loop_cnt;
8678 u32 m_stat;
8679
8680 for (loop_cnt = 0; loop_cnt < POLLING_HALMAC_CNT; loop_cnt++) {
8681 m_stat = mac->ops->get_p2p_stat(mac) ;
8682 if (m_stat == MACSUCCESS) {
8683 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]_hal_mac_get_p2p_stat(): polling ok, count(%d)\n",
8684 loop_cnt);
8685 return RTW_HAL_STATUS_SUCCESS;
8686 } else if (m_stat == MACP2PSTFAIL) {
8687 PHL_TRACE(COMP_PHL_P2PPS, _PHL_ERR_, "[NoA]_hal_mac_get_p2p_stat(): polling error, count(%d)\n",
8688 loop_cnt);
8689 return RTW_HAL_STATUS_FAILURE;
8690 }
8691 _os_sleep_ms(hal_to_drvpriv(hal), POLLING_HALMAC_TIME);
8692 }
8693 PHL_TRACE(COMP_PHL_P2PPS, _PHL_ERR_, "[NoA]_hal_mac_get_p2p_stat(): polling timeout!\n");
8694 return RTW_HAL_STATUS_FAILURE;
8695 }
8696
8697
_hal_mac_set_p2p_act(struct hal_info_t * hal,struct mac_ax_p2p_act_info * mac_p2p_info)8698 enum rtw_hal_status _hal_mac_set_p2p_act(struct hal_info_t *hal,
8699 struct mac_ax_p2p_act_info *mac_p2p_info)
8700 {
8701 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8702 struct mac_ax_adapter *mac = hal_to_mac(hal);
8703 u32 m_stat;
8704
8705 m_stat = mac->ops->p2p_act_h2c(mac, mac_p2p_info);
8706 if (m_stat != MACSUCCESS) {
8707 PHL_TRACE(COMP_PHL_P2PPS, _PHL_ERR_, "[NoA]_hal_mac_set_noa_act(): Fault, status = %d, Action = %d\n",
8708 m_stat, mac_p2p_info->act);
8709 return RTW_HAL_STATUS_MAC_API_FAILURE;
8710 }
8711 h_stat = _hal_mac_get_p2p_stat(hal);
8712 return h_stat;
8713 }
8714
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)8715 enum rtw_hal_status rtw_hal_mac_noa_init(struct hal_info_t *hal,
8716 struct rtw_phl_noa_info *noa_info,
8717 struct rtw_phl_noa_desc *in_desc,
8718 u16 macid)
8719 {
8720 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8721 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8722
8723 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_init()\n");
8724 _hal_mac_noa_fill_info(P2P_ACT_INIT, in_desc, macid, &mac_p2p_info);
8725 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8726 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8727 return h_stat;
8728 }
8729
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)8730 enum rtw_hal_status rtw_hal_mac_noa_update(struct hal_info_t *hal,
8731 struct rtw_phl_noa_info *noa_info,
8732 struct rtw_phl_noa_desc *in_desc,
8733 u16 macid)
8734 {
8735 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8736 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8737
8738 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_update()\n");
8739 _hal_mac_noa_fill_info(P2P_ACT_UPDATE, in_desc, macid, &mac_p2p_info);
8740 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8741 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8742 return h_stat;
8743 }
8744
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)8745 enum rtw_hal_status rtw_hal_mac_noa_remove(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_remove()\n");
8754 _hal_mac_noa_fill_info(P2P_ACT_REMOVE, 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_noa_terminate(struct hal_info_t * hal,struct rtw_phl_noa_info * noa_info,struct rtw_phl_noa_desc * in_desc,u16 macid)8761 enum rtw_hal_status rtw_hal_mac_noa_terminate(struct hal_info_t *hal,
8762 struct rtw_phl_noa_info *noa_info,
8763 struct rtw_phl_noa_desc *in_desc,
8764 u16 macid)
8765 {
8766 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8767 struct mac_ax_p2p_act_info mac_p2p_info = {0};
8768
8769 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_noa_terminate()\n");
8770 _hal_mac_noa_fill_info(P2P_ACT_TERMINATE, in_desc, macid, &mac_p2p_info);
8771 _hal_mac_dump_p2p_act_struct(&mac_p2p_info);
8772 h_stat = _hal_mac_set_p2p_act(hal, &mac_p2p_info);
8773 return h_stat;
8774
8775 }
8776
rtw_hal_mac_tsf32_tog_enable(struct hal_info_t * hal,u8 hw_band,u8 port,u16 early)8777 enum rtw_hal_status rtw_hal_mac_tsf32_tog_enable(struct hal_info_t *hal,
8778 u8 hw_band,
8779 u8 port,
8780 u16 early)
8781 {
8782 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8783 struct mac_ax_t32_togl_info mac_t32_tog_info = {0};
8784 struct mac_ax_adapter *mac = hal_to_mac(hal);
8785 u32 m_stat;
8786
8787 mac_t32_tog_info.band = hw_band;
8788 mac_t32_tog_info.port = port;
8789 mac_t32_tog_info.en = true;
8790 mac_t32_tog_info.early = early;
8791 m_stat = mac->ops->tsf32_togl_h2c(mac, &mac_t32_tog_info);
8792 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_tsf32_tog_enable() m_stat = %d\n",
8793 m_stat);
8794 if(m_stat == MACSUCCESS)
8795 h_stat = RTW_HAL_STATUS_SUCCESS;
8796 return h_stat;
8797 }
8798
rtw_hal_mac_tsf32_tog_disable(struct hal_info_t * hal,u8 hw_band,u8 port)8799 enum rtw_hal_status rtw_hal_mac_tsf32_tog_disable(struct hal_info_t *hal,
8800 u8 hw_band,
8801 u8 port)
8802 {
8803 enum rtw_hal_status h_stat = RTW_HAL_STATUS_FAILURE;
8804 struct mac_ax_t32_togl_info mac_t32_tog_info = {0};
8805 struct mac_ax_adapter *mac = hal_to_mac(hal);
8806 u32 m_stat;
8807
8808 mac_t32_tog_info.band = hw_band;
8809 mac_t32_tog_info.port = port;
8810 mac_t32_tog_info.en = false;
8811 m_stat = mac->ops->tsf32_togl_h2c(mac, &mac_t32_tog_info);
8812 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_tsf32_tog_disable() m_stat = %d\n",
8813 m_stat);
8814 if(m_stat == MACSUCCESS)
8815 h_stat = RTW_HAL_STATUS_SUCCESS;
8816 return h_stat;
8817 }
8818
rtw_hal_mac_get_tsf32_tog_rpt(struct hal_info_t * hal,struct rtw_phl_tsf32_tog_rpt * rpt)8819 enum rtw_hal_status rtw_hal_mac_get_tsf32_tog_rpt(struct hal_info_t *hal,
8820 struct rtw_phl_tsf32_tog_rpt *rpt)
8821 {
8822 struct mac_ax_adapter *mac = hal_to_mac(hal);
8823 struct mac_ax_t32_togl_rpt m_rpt = {0};
8824 u32 m_stat = 0;
8825 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_get_tsf32_tog_rpt()\n");
8826 m_stat = mac->ops->get_t32_togl_rpt(mac, &m_rpt);
8827 if (m_stat != MACSUCCESS) {
8828 PHL_TRACE(COMP_PHL_P2PPS, _PHL_INFO_, "[NoA]rtw_hal_mac_get_tsf32_tog_rpt() MAC FAIL(%d)!\n",
8829 m_stat);
8830 return RTW_HAL_STATUS_FAILURE;
8831 }
8832 rpt->band = m_rpt.band;
8833 rpt->port = m_rpt.port;
8834 rpt->valid = m_rpt.valid;
8835 rpt->early = m_rpt.early;
8836 rpt->status = m_rpt.status;
8837 rpt->tsf_l = m_rpt.tsf_l;
8838 rpt->tsf_h = m_rpt.tsf_h;
8839 return RTW_HAL_STATUS_SUCCESS;
8840 }
8841 #endif
rtw_hal_mac_notification(struct hal_info_t * hal_info,enum phl_msg_evt_id event,u8 band)8842 void rtw_hal_mac_notification(struct hal_info_t *hal_info,
8843 enum phl_msg_evt_id event,
8844 u8 band)
8845 {
8846 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8847
8848 mac->ops->event_notify(mac, event, band);
8849 }
8850
rtw_hal_mac_cmd_notification(struct hal_info_t * hal_info,void * hal_cmd,u8 band)8851 void rtw_hal_mac_cmd_notification(struct hal_info_t *hal_info,
8852 void *hal_cmd,
8853 u8 band)
8854 {
8855 /*todo*/
8856 }
8857
8858 enum rtw_hal_status
rtw_hal_mac_trigger_fw_conflict(struct hal_info_t * hal_info,u32 addr,u8 vol)8859 rtw_hal_mac_trigger_fw_conflict(struct hal_info_t *hal_info, u32 addr, u8 vol)
8860 {
8861 struct hal_ops_t *hal_ops = hal_get_ops(hal_info);
8862 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8863 u32 i = 0;
8864 u32 convert_mask = 0xffffffff;
8865 u32 val;
8866
8867 /* Switch voltage */
8868 mac->ops->set_hw_value(mac, MAC_AX_HW_SET_CORE_SWR_VOLT, &vol);
8869
8870 /* Trigger method: H2C Halt */
8871 hal_ops->write_macreg(hal_info, 0x168, convert_mask, 0x5dc0007);
8872 hal_ops->write_macreg(hal_info, 0x160, convert_mask, 0x1);
8873
8874 /* loop read reg */
8875 for(i = 0; i<1000; i++){
8876 val = hal_ops->read_macreg(hal_info,
8877 addr,
8878 convert_mask);
8879 PHL_INFO("%s: voltag %d count %d io_value = %x\n", __FUNCTION__,vol, i, val);
8880 }
8881
8882 return RTW_HAL_STATUS_SUCCESS;
8883 }
8884
8885
8886 enum rtw_hal_status
rtw_hal_mac_set_gpio_func(struct rtw_hal_com_t * hal_com,u8 func,s8 gpio_cfg)8887 rtw_hal_mac_set_gpio_func(struct rtw_hal_com_t *hal_com, u8 func, s8 gpio_cfg){
8888 struct hal_info_t *hal_info = hal_com->hal_priv;
8889 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
8890 struct mac_ax_ops *ops = mac->ops;
8891 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
8892
8893 ret = ops->set_gpio_func(mac, func, gpio_cfg);
8894
8895 if (ret != MACSUCCESS)
8896 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "Set GPIO failure, status = %d\n", ret);
8897
8898 return ret;
8899 }
8900
8901 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)8902 rtw_hal_mac_bfee_set_vht_gid(struct hal_info_t *hal,
8903 u8 band, struct rtw_phl_gid_pos_tbl *tbl)
8904 {
8905 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
8906 struct mac_gid_pos gid_pos = {0};
8907 struct mac_ax_adapter *mac = hal_to_mac(hal);
8908 u32 mac_status = 0;
8909 u8 i = 0;
8910
8911 gid_pos.band = band;
8912 /* For GID 0~31 */
8913 for (i = 0; i < 4; i++) {
8914 gid_pos.gid_tab[0] |= (tbl->gid_vld[i] << (i << 3));
8915 }
8916
8917 for (i = 0; i < 8; i++) {
8918 if (i < 4)
8919 gid_pos.user_pos[0] |= (tbl->pos[i] << (i << 3));
8920 else
8921 gid_pos.user_pos[1] |= (tbl->pos[i] << ((i - 4) << 3));
8922 }
8923 /* For GID 32~64 */
8924 for (i = 4; i < 8; i++) {
8925 gid_pos.gid_tab[1] |= (tbl->gid_vld[i] << ((i - 4) << 3));
8926 }
8927 for (i = 8; i < 16; i++) {
8928 if (i < 12)
8929 gid_pos.user_pos[2] |= (tbl->pos[i] << ((i - 8) << 3));
8930 else
8931 gid_pos.user_pos[3] |= (tbl->pos[i] << ((i - 12) << 3));
8932 }
8933 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s() : Set VHT GID for band %d;\n",
8934 __func__, band);
8935 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s() : band %d ; gid tbl 0x%x 0x%x;\n",
8936 __func__, band,
8937 gid_pos.gid_tab[0], gid_pos.gid_tab[1]);
8938 PHL_TRACE(COMP_PHL_DBG, _PHL_INFO_, "%s() : user position 0x%x 0x%x 0x%x 0x%x;\n",
8939 __func__,
8940 gid_pos.user_pos[0], gid_pos.user_pos[1],
8941 gid_pos.user_pos[2], gid_pos.user_pos[3]);
8942
8943 mac_status = mac->ops->gidpos(mac, &gid_pos);
8944 if (mac_status != MACSUCCESS) {
8945 hal_status = RTW_HAL_STATUS_FAILURE;
8946 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
8947 __func__, mac_status);
8948 }
8949
8950 return hal_status;
8951 }
8952
8953 /* acq_val/mgq_val , input unit : us */
8954 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)8955 rtw_hal_mac_set_tx_lifetime(struct hal_info_t *hal, enum phl_band_idx band,
8956 bool acq_en, bool mgq_en, u16 acq_val, u16 mgq_val)
8957 {
8958 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
8959 struct mac_ax_adapter *mac = hal_to_mac(hal);
8960 struct mac_ax_lifetime_cfg cfg = {0};
8961 u32 mac_status = 0;
8962 u16 tmp = 0;
8963 #define HAL_MAC_TX_LIFETIME_UNIT_US_SHT 8 /* 256 us */
8964
8965 if (HW_BAND_1 == band)
8966 cfg.band = 1;
8967 else
8968 cfg.band = 0;
8969
8970 if(true == acq_en) {
8971 cfg.en.acq_en = 1;
8972 tmp = acq_val >> HAL_MAC_TX_LIFETIME_UNIT_US_SHT;
8973 cfg.val.acq_val_1 = tmp;
8974 cfg.val.acq_val_2 = tmp;
8975 cfg.val.acq_val_3 = tmp;
8976 cfg.val.acq_val_4 = tmp;
8977 }
8978
8979 if (true == mgq_en) {
8980 cfg.en.mgq_en = 1;
8981 tmp = mgq_val >> HAL_MAC_TX_LIFETIME_UNIT_US_SHT;
8982 cfg.val.mgq_val = tmp;
8983 }
8984
8985 mac_status = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_LIFETIME_CFG, (void *)&cfg);
8986
8987 if (mac_status != MACSUCCESS) {
8988 hal_status = RTW_HAL_STATUS_FAILURE;
8989 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
8990 __func__, mac_status);
8991 }
8992
8993 return hal_status;
8994 }
8995
8996 #ifdef CONFIG_FW_IO_OFLD_SUPPORT
rtw_hal_mac_add_cmd_ofld(struct rtw_hal_com_t * hal_com,struct rtw_mac_cmd * cmd)8997 enum rtw_hal_status rtw_hal_mac_add_cmd_ofld(struct rtw_hal_com_t *hal_com, struct rtw_mac_cmd *cmd)
8998 {
8999 struct hal_info_t *hal_info = hal_com->hal_priv;
9000 enum rtw_hal_status hal_status = RTW_HAL_STATUS_FAILURE;
9001 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9002 u32 mac_status;
9003
9004 if (mac == NULL)
9005 goto exit;
9006 mac_status = mac->ops->add_cmd_ofld(mac, cmd);
9007 if (mac_status != MACSUCCESS) {
9008 PHL_TRACE(COMP_PHL_MAC, _PHL_ERR_, "%s(): fault, status = %d.\n",
9009 __func__, mac_status);
9010 goto exit;
9011 }
9012 hal_status = RTW_HAL_STATUS_SUCCESS;
9013 exit:
9014 return hal_status;
9015 }
9016 #endif
9017
9018
rtw_hal_mac_set_hw_rts_th(struct hal_info_t * hal,u8 band,u16 time_th,u16 len_th)9019 enum rtw_hal_status rtw_hal_mac_set_hw_rts_th(struct hal_info_t *hal, u8 band,
9020 u16 time_th, u16 len_th)
9021 {
9022 struct mac_ax_adapter *mac = hal_to_mac(hal);
9023 struct mac_ax_hw_rts_th hw_rts_th = {0};
9024 u32 mac_err;
9025
9026 PHL_INFO("%s\n", __func__);
9027 _os_mem_set(hal_to_drvpriv(hal), &hw_rts_th, 0, sizeof(hw_rts_th));
9028
9029 hw_rts_th.band = band;
9030 hw_rts_th.time_th = time_th;
9031 hw_rts_th.len_th = len_th;
9032
9033 mac_err = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_HW_RTS_TH,
9034 &hw_rts_th);
9035
9036 if (mac_err != MACSUCCESS) {
9037 PHL_ERR("%s : mac status %d.\n", __func__, mac_err);
9038 return RTW_HAL_STATUS_FAILURE;
9039 }
9040
9041 return RTW_HAL_STATUS_SUCCESS;
9042 }
9043
rtw_hal_mac_get_efuse_ver_len(struct rtw_hal_com_t * hal_com)9044 u8 rtw_hal_mac_get_efuse_ver_len(struct rtw_hal_com_t *hal_com)
9045 {
9046 struct hal_info_t *hal_info = hal_com->hal_priv;
9047 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9048
9049 return mac->hw_info->efuse_version_size;
9050 }
9051
9052
9053 enum rtw_hal_status
rtw_hal_mac_set_dfs_tb_ctrl(struct hal_info_t * hal_info,u8 set)9054 rtw_hal_mac_set_dfs_tb_ctrl(struct hal_info_t *hal_info, u8 set)
9055 {
9056 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9057 u8 dis_ru_26 = 0;
9058 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
9059
9060 if (set)
9061 dis_ru_26 = 1;
9062 ret = mac->ops->set_hw_value(mac, MAC_AX_HW_SET_TX_RU26_TB, &dis_ru_26);
9063 if (ret != MACSUCCESS) {
9064 PHL_ERR("%s : mac status %d.\n", __func__, ret);
9065 return RTW_HAL_STATUS_FAILURE;
9066 }
9067
9068 return RTW_HAL_STATUS_SUCCESS;
9069 }
9070
9071 enum rtw_hal_status
rtw_hal_mac_patch_rx_rate(struct hal_info_t * hal_info,struct rtw_r_meta_data * mdata)9072 rtw_hal_mac_patch_rx_rate(struct hal_info_t *hal_info, struct rtw_r_meta_data *mdata)
9073 {
9074 struct mac_ax_adapter *mac = hal_to_mac(hal_info);
9075 enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
9076
9077 ret = mac->ops->patch_rx_rate(mac, mdata);
9078 if (ret != MACSUCCESS) {
9079 PHL_ERR("%s : mac status %d.\n", __func__, ret);
9080 return RTW_HAL_STATUS_FAILURE;
9081 }
9082
9083 return RTW_HAL_STATUS_SUCCESS;
9084 }
9085
9086 /**
9087 * rtw_hal_mac_set_tx_duty() - Set tx pause/un-pause interval
9088 * @hal_info: struct hal_info_t*
9089 * @pause_interval: tx pause interval (ms)
9090 * @tx_interval: tx interval (ms)
9091 *
9092 * Return RTW_HAL_STATUS_SUCCESS when operation success.
9093 */
9094 enum rtw_hal_status
rtw_hal_mac_set_tx_duty(struct hal_info_t * hal_info,u16 pause_interval,u16 tx_interval)9095 rtw_hal_mac_set_tx_duty(struct hal_info_t *hal_info,
9096 u16 pause_interval,
9097 u16 tx_interval)
9098 {
9099 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
9100 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
9101 u32 mac_status = 0;
9102
9103 mac_status = mac->ops->tx_duty(mac, pause_interval, tx_interval);
9104 if (mac_status != MACSUCCESS) {
9105 hal_status = RTW_HAL_STATUS_FAILURE;
9106 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
9107 __func__, mac_status);
9108 }
9109
9110 return hal_status;
9111 }
9112
9113 /**
9114 * rtw_hal_mac_stop_tx_duty() - Stop previous tx duty config
9115 * @hal_info: struct hal_info_t*
9116 *
9117 * Return RTW_HAL_STATUS_SUCCESS when operation success.
9118 */
9119 enum rtw_hal_status
rtw_hal_mac_stop_tx_duty(struct hal_info_t * hal_info)9120 rtw_hal_mac_stop_tx_duty(struct hal_info_t *hal_info)
9121 {
9122 enum rtw_hal_status hal_status = RTW_HAL_STATUS_SUCCESS;
9123 struct mac_ax_adapter *mac = (struct mac_ax_adapter *)hal_info->mac;
9124 u32 mac_status = 0;
9125
9126 mac_status = mac->ops->tx_duty_stop(mac);
9127 if (mac_status != MACSUCCESS) {
9128 hal_status = RTW_HAL_STATUS_FAILURE;
9129 PHL_TRACE(COMP_PHL_DBG, _PHL_ERR_, "%s() : fail, status = %d.\n",
9130 __func__, mac_status);
9131 }
9132
9133 return hal_status;
9134 }