hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
/******************************************************************************
 *
 * Copyright(c) 2019 - 2021 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#define _HAL_TX_C_
#include "hal_headers.h"
/**
 * this function will be used in read / write pointer mechanism and
 * return the number of available read pointer
 * @rptr: input, the read pointer
 * @wptr: input, the write pointer
 * @bndy: input, the boundary of read / write pointer mechanism
 */
u16 hal_calc_avail_rptr(u16 rptr, u16 wptr, u16 bndy)
{
   u16 avail_rptr = 0;
 
   if (wptr >= rptr)
       avail_rptr = wptr - rptr;
   else if (rptr > wptr)
       avail_rptr = wptr + (bndy - rptr);
 
   return avail_rptr;
}
 
 
/**
 * this function will be used in read / write pointer mechanism and
 * return the number of available write pointer
 * @rptr: input, the read pointer
 * @wptr: input, the write pointer
 * @bndy: input, the boundary of read / write pointer mechanism
 */
u16 hal_calc_avail_wptr(u16 rptr, u16 wptr, u16 bndy)
{
   u16 avail_wptr = 0;
 
   if (rptr > wptr)
       avail_wptr = rptr - wptr - 1;
   else if (wptr >= rptr)
       avail_wptr = rptr + (bndy - wptr) - 1;
 
   return avail_wptr;
}
 
 
enum rtw_hal_status
rtw_hal_enable_hwamsdu(void *hal,
              u8 enable,
              u8 max_num,
              u8 en_single_amsdu,
              u8 en_last_amsdu_padding)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   return rtw_hal_mac_enable_hwamsdu(hal_info, enable, max_num, en_single_amsdu, en_last_amsdu_padding);
}
 
/**
 * rtw_hal_tx_chnl_mapping - query hw tx dma channel mapping to the sw xmit ring
 * identified by macid, tid and band
 * @hal: see struct hal_info_t
 * @macid: input target macid is 0 ~ 127
 * @cat: input target packet category, see enum rtw_phl_ring_cat
 * @band: input target band, 0 for band 0 / 1 for band 1
 *
 * returns the mapping hw tx dma channel
 */
u8 rtw_hal_tx_chnl_mapping(void *hal, u16 macid,
              enum rtw_phl_ring_cat cat, u8 band)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
   u8 tx_chnl = 0;
 
   tx_chnl = trx_ops->map_hw_tx_chnl(hal_info, macid, cat, band);
 
   return tx_chnl;
}
 
/**
 * rtw_hal_get_fwcmd_queue_idx - get idx of fwcmd queue
 * @hal: see struct hal_info_t
 *
 * returns u8 idx of fwcmd queue
 */
u8 rtw_hal_get_fwcmd_queue_idx(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   return trx_ops->get_fwcmd_queue_idx();
}
 
void rtw_hal_clear_rwptr(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   if (RTW_HAL_STATUS_SUCCESS != rtw_hal_mac_clear_rwptr(hal_info))
       PHL_ERR("%s failure \n", __func__);
}
 
void rtw_hal_cfg_txhci(void *hal, u8 en)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   PHL_TRACE(COMP_PHL_DBG, _PHL_DEBUG_, "%s : enable %d.\n", __func__, en);
 
   if (RTW_HAL_STATUS_SUCCESS != rtw_hal_mac_cfg_txhci(hal_info, en))
       PHL_ERR("%s failure \n", __func__);
}
 
 
 
enum rtw_hal_status rtw_hal_chk_allq_empty(void *hal, u8 *empty)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   FUNCIN();
 
   return rtw_hal_mac_chk_allq_empty(hal_info, empty);
}
 
enum rtw_hal_status rtw_hal_set_resp_ack_chk_cca(void *hal, u8 band, u8 en)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   FUNCIN();
 
   return rtw_hal_mac_set_resp_ack_chk_cca(hal_info, band, en);
}
 
enum rtw_hal_status rtw_hal_sifs_chk_cca_en(void *hal, u8 band, u8 en)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   FUNCIN();
 
   return rtw_hal_mac_sifs_chk_cca_en(hal_info, band, en);
}
 
 
enum rtw_hal_status
rtw_hal_fill_txdesc(void *hal,
                    struct rtw_xmit_req *treq,
                    u8 *wd_buf,
                    u32 *wd_len)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   return rtw_hal_mac_fill_txdesc(hal_info->mac, treq, wd_buf, wd_len);
}
 
 
enum rtw_hal_status
rtw_hal_get_hwseq(void *hal, u16 macid, u8 ref_sel, u8 ssn_sel, u16 *hw_seq)
{
   enum rtw_hal_status sts = RTW_HAL_STATUS_SUCCESS;
 
   sts = rtw_hal_mac_get_hwseq(hal, macid, ref_sel, ssn_sel, hw_seq);
 
   return sts;
}
 
 
enum rtw_hal_status
rtw_hal_poll_hw_tx_done(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status sts = RTW_HAL_STATUS_SUCCESS;
 
   sts = rtw_hal_mac_poll_hw_tx_done(hal_info);
 
   return sts;
}
 
enum rtw_hal_status
rtw_hal_hw_tx_resume(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status sts = RTW_HAL_STATUS_SUCCESS;
 
   sts = rtw_hal_mac_hw_tx_resume(hal_info);
 
   return sts;
}
 
u8 rtw_hal_poll_txdma_idle(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   enum rtw_hal_status ret = RTW_HAL_STATUS_SUCCESS;
 
   FUNCIN();
 
   ret = rtw_hal_mac_poll_txdma_idle(hal_info);
 
   return (ret == RTW_HAL_STATUS_SUCCESS) ? true : false;
}
 
#ifdef CONFIG_PCI_HCI
/**
 * rtw_hal_convert_qsel_to_tid - convert qsel to tid value
 * @hal: see struct hal_info_t
 * @qsel: HW queue selection
 *
 * returns enum RTW_HAL_STATUS
 */
u8 rtw_hal_convert_qsel_to_tid(void *hal, u8 qsel_id, u8 tid_indic)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->qsel_to_tid(hal_info, qsel_id, tid_indic);
 
   return hstatus;
}
/**
 * rtw_hal_tx_res_query - query current HW tx resource with specifc dma channel
 * @hal: see struct hal_info_t
 * @dma_ch: the target dma channel
 * @host_idx: current host index of this channel
 * @hw_idx: current hw index of this channel
 *
 * this function returns the number of available tx resource
 * NOTE, input host_idx and hw_idx ptr shall NOT be NULL
 */
u16 rtw_hal_tx_res_query(void *hal, u8 dma_ch, u16 *host_idx, u16 *hw_idx)
{
   enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   u16 res_num = 0;
 
   sts = rtw_hal_mac_tx_res_query(hal_info, dma_ch, host_idx, hw_idx,
                                  &res_num);
 
   return res_num;
}
 
enum phl_band_idx rtw_hal_query_txch_hwband(void *hal, u8 dma_ch)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
   enum phl_band_idx band_idx = HW_BAND_0;
 
   band_idx = trx_ops->query_txch_hwband(dma_ch);
 
   return band_idx;
}
 
/**
 * rtw_hal_query_txch_num - query total hw tx dma channels number
 *
 * returns the number of  hw tx dma channel
 */
u8 rtw_hal_query_txch_num(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
   u8 ch_num = 0;
 
   ch_num = trx_ops->query_txch_num();
 
   return ch_num;
}
 
enum rtw_hal_status rtw_hal_trx_init(void *hal, u8 *txbd_buf, u8 *rxbd_buf)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->init(hal_info, txbd_buf, rxbd_buf);
 
   return hstatus;
}
 
void rtw_hal_trx_deinit(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   trx_ops->deinit(hal_info);
}
 
/**
 * rtw_hal_update_wd_page - update wd page for xmit packet
 * @hal: see struct hal_info_t
 * @phl_pkt_req: packet xmit request from phl, see struct rtw_phl_pkt_req
 *
 * returns enum RTW_HAL_STATUS
 */
enum rtw_hal_status rtw_hal_update_wd_page(void *hal, void *phl_pkt_req)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->update_wd(hal_info, phl_pkt_req);
 
   return hstatus;
}
 
/**
 * rtw_hal_update_txbd - update tx bd for xmit packet
 * @hal: see struct hal_info_t
 * @wd: buffer pointer of wd page to fill in txbd
 *
 * returns enum RTW_HAL_STATUS
 * NOTE, this function is PCIe specific function
 */
enum rtw_hal_status rtw_hal_update_txbd(void *hal, void *txbd, void *wd, u8 dma_ch, u16 wd_num)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->update_txbd(hal, txbd, wd, dma_ch, wd_num);
 
   return hstatus;
}
 
 
/**
 * rtw_hal_update_trigger_txstart - trigger hw to start tx
 * @hal: see struct hal_info_t
 * @txbd: the target txbd to update
 * @dma_ch: the dma channel index of this txbd_ring
 *
 * returns enum RTW_HAL_STATUS
 */
enum rtw_hal_status
rtw_hal_trigger_txstart(void *hal, struct tx_base_desc *txbd, u8 dma_ch)
{
   enum rtw_hal_status sts = RTW_HAL_STATUS_FAILURE;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   sts = rtw_hal_mac_trigger_txstart(hal_info, txbd, dma_ch);
 
   if (sts != RTW_HAL_STATUS_SUCCESS) {
       PHL_TRACE(COMP_PHL_XMIT, _PHL_INFO_, "%s : trigger tx start fail!\n",
                 __func__);
   }
 
   return sts;
}
 
#endif /*CONFIG_PCI_HCI*/
 
#ifdef CONFIG_USB_HCI
enum rtw_hal_status rtw_hal_trx_init(void *hal)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->init(hal_info);
 
   return hstatus;
}
 
void rtw_hal_trx_deinit(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   trx_ops->deinit(hal_info);
}
 
u8 rtw_hal_get_bulkout_id(void *hal, u8 dma_ch, u8 mode)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->get_bulkout_id(hal, dma_ch, mode);
 
   return hstatus;
}
 
enum rtw_hal_status
   rtw_hal_usb_tx_agg_cfg(void *hal, u8* wd_buf, u8 agg_num)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   hstatus = trx_ops->usb_tx_agg_cfg(hal, wd_buf, agg_num);
 
   return hstatus;
}
 
 
u8 rtw_hal_get_max_bulkout_wd_num(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
 
   return trx_ops->get_max_bulkout_wd_num(hal);
}
 
u16 rtw_hal_get_max_dma_txagg_msk(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
   return hal_mac_usb_get_max_dma_txagg_msk(hal_info);
}
 
u32 rtw_hal_get_wd_len(void *hal,
               struct rtw_xmit_req *tx_req)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
   u32 wd_len = 0;
 
   wd_len = trx_ops->hal_get_wd_len(hal_info, tx_req);
 
   return wd_len;
}
 
#endif
 
#ifdef CONFIG_SDIO_HCI
void rtw_hal_sdio_tx_cfg(void *hal)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
 
 
   rtw_hal_mac_sdio_tx_cfg(hal_info->hal_com);
}
 
enum rtw_hal_status rtw_hal_sdio_tx(void *hal, u8 dma_ch, u8 *buf, u32 buf_len,
                   u8 agg_count, u16 *pkt_len, u8 *wp_offset)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   u32 txaddr;
   u32 txlen;
   bool ready;
 
 
   ready = rtw_hal_mac_sdio_check_tx_allow(hal_info->hal_com, dma_ch,
                       buf, buf_len, agg_count,
                       pkt_len, wp_offset, &txaddr,
                       &txlen);
   if (!ready)
       return RTW_HAL_STATUS_RESOURCE;
 
   hal_sdio_cmd53_w(hal_info->hal_com, txaddr, txlen, buf);
 
   return RTW_HAL_STATUS_SUCCESS;
}
#endif /* CONFIG_SDIO_HCI */
 
/**
 * rtw_hal_fill_wd - fill wd-info and wd-boddy for xmit packet
 * @hal: see struct hal_info_t
 * @phl_pkt_req: packet xmit request from phl, see struct rtw_phl_pkt_req
 *
 * returns enum RTW_HAL_STATUS
 */
enum rtw_hal_status rtw_hal_fill_wd(void *hal,
               struct rtw_xmit_req *tx_req,
               u8 *wd_buf, u32 *wd_len)
{
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_SUCCESS;
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
   struct hal_trx_ops *trx_ops = hal_info->trx_ops;
#endif
 
#ifdef RTW_WKARD_CCX_RPT_LIMIT_CTRL
   if (tx_req->mdata.spe_rpt) {
       if (tx_req->mdata.data_tx_cnt_lmt_en)
           hal_info->hal_com->spe_pkt_cnt_lmt = tx_req->mdata.data_tx_cnt_lmt;
   }
#endif
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
   if (trx_ops->hal_fill_wd)
       hstatus = trx_ops->hal_fill_wd(hal_info, tx_req, wd_buf, wd_len);
   else
#endif
       hstatus = rtw_hal_mac_fill_txdesc(hal_info->mac, tx_req, wd_buf, wd_len);
 
   return hstatus;
}
 
enum rtw_hal_status rtw_hal_cfg_hw_cts2self(void *hal, u8 band_sel, u8 enable,
                       u8 non_sec_thr, u8 sec_thr)
{
   struct hal_info_t *hal_info = (struct hal_info_t *)hal;
   struct mac_ax_cts2self_cfg mac_hw_cts_cfg;
   enum rtw_hal_status hstatus = RTW_HAL_STATUS_FAILURE;
 
   if (enable)
       mac_hw_cts_cfg.threshold_sel = MAC_AX_CTS2SELF_BOTH_THRESHOLD;
   else
       mac_hw_cts_cfg.threshold_sel = MAC_AX_CTS2SELF_DISABLE;
 
   mac_hw_cts_cfg.band_sel = band_sel;
   mac_hw_cts_cfg.non_sec_threshold = non_sec_thr;
   mac_hw_cts_cfg.sec_threshold = sec_thr;
 
   hstatus = rtw_hal_mac_cfg_hw_cts2slef(hal_info, &mac_hw_cts_cfg);
 
   return hstatus;
}