Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/hal/hal_halmac.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2015 - 2019 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_HALMAC_C_
16
17
#include <drv_types.h> /* PADAPTER, struct dvobj_priv, SDIO_ERR_VAL8 and etc. */
18
#include <hal_data.h> /* efuse, PHAL_DATA_TYPE and etc. */
19
#include "hal_halmac.h" /* dvobj_to_halmac() and ect. */
20
21
/*
22
* HALMAC take return value 0 for fail and 1 for success to replace
23
* _FALSE/_TRUE after V1_04_09
24
*/
25
#define RTW_HALMAC_FAIL 0
26
#define RTW_HALMAC_SUCCESS 1
27
28
#define DEFAULT_INDICATOR_TIMELMT 1000 /* ms */
29
#define MSG_PREFIX "[HALMAC]"
30
31
#define RTW_HALMAC_DLFW_MEM_NO_STOP_TX
32
33
/*
34
* Driver API for HALMAC operations
35
*/
36
37
#ifdef CONFIG_SDIO_HCI
38
#include <rtw_sdio.h>
39
40
static u8 _halmac_mac_reg_page0_chk(const char *func, struct dvobj_priv *dvobj, u32 offset)
41
{
42
#if defined(CONFIG_IO_CHECK_IN_ANA_LOW_CLK) && defined(CONFIG_LPS_LCLK)
43
struct pwrctrl_priv *pwrpriv = &dvobj->pwrctl_priv;
44
u32 mac_reg_offset = 0;
45
46
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
47
return _TRUE;
48
49
if (pwrpriv->lps_level == LPS_NORMAL)
50
return _TRUE;
51
52
if (pwrpriv->rpwm >= PS_STATE_S2)
53
return _TRUE;
54
55
if (offset & (WLAN_IOREG_DEVICE_ID << 13)) { /*WLAN_IOREG_OFFSET*/
56
mac_reg_offset = offset & HALMAC_WLAN_MAC_REG_MSK;
57
if (mac_reg_offset < 0x100) {
58
RTW_ERR(FUNC_ADPT_FMT
59
"access MAC REG -0x%04x in PS-mode:0x%02x (rpwm:0x%02x, lps_level:0x%02x)\n",
60
FUNC_ADPT_ARG(dvobj_get_primary_adapter(dvobj)), mac_reg_offset,
61
pwrpriv->pwr_mode, pwrpriv->rpwm, pwrpriv->lps_level);
62
rtw_warn_on(1);
63
return _FALSE;
64
}
65
}
66
#endif
67
return _TRUE;
68
}
69
70
static u8 _halmac_sdio_cmd52_read(void *p, u32 offset)
71
{
72
struct dvobj_priv *d;
73
u8 val;
74
u8 ret;
75
76
77
d = (struct dvobj_priv *)p;
78
_halmac_mac_reg_page0_chk(__func__, d, offset);
79
ret = rtw_sdio_read_cmd52(d, offset, &val, 1);
80
if (_FAIL == ret) {
81
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
82
return SDIO_ERR_VAL8;
83
}
84
85
return val;
86
}
87
88
static void _halmac_sdio_cmd52_write(void *p, u32 offset, u8 val)
89
{
90
struct dvobj_priv *d;
91
u8 ret;
92
93
94
d = (struct dvobj_priv *)p;
95
_halmac_mac_reg_page0_chk(__func__, d, offset);
96
ret = rtw_sdio_write_cmd52(d, offset, &val, 1);
97
if (_FAIL == ret)
98
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
99
}
100
101
static u8 _halmac_sdio_reg_read_8(void *p, u32 offset)
102
{
103
struct dvobj_priv *d;
104
u8 *pbuf;
105
u8 val;
106
u8 ret;
107
108
109
d = (struct dvobj_priv *)p;
110
val = SDIO_ERR_VAL8;
111
_halmac_mac_reg_page0_chk(__func__, d, offset);
112
pbuf = rtw_zmalloc(1);
113
if (!pbuf)
114
return val;
115
116
ret = rtw_sdio_read_cmd53(d, offset, pbuf, 1);
117
if (ret == _FAIL) {
118
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
119
goto exit;
120
}
121
122
val = *pbuf;
123
124
exit:
125
rtw_mfree(pbuf, 1);
126
127
return val;
128
}
129
130
static u16 _halmac_sdio_reg_read_16(void *p, u32 offset)
131
{
132
struct dvobj_priv *d;
133
u8 *pbuf;
134
u16 val;
135
u8 ret;
136
137
138
d = (struct dvobj_priv *)p;
139
val = SDIO_ERR_VAL16;
140
_halmac_mac_reg_page0_chk(__func__, d, offset);
141
pbuf = rtw_zmalloc(2);
142
if (!pbuf)
143
return val;
144
145
ret = rtw_sdio_read_cmd53(d, offset, pbuf, 2);
146
if (ret == _FAIL) {
147
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
148
goto exit;
149
}
150
151
val = le16_to_cpu(*(u16 *)pbuf);
152
153
exit:
154
rtw_mfree(pbuf, 2);
155
156
return val;
157
}
158
159
static u32 _halmac_sdio_reg_read_32(void *p, u32 offset)
160
{
161
struct dvobj_priv *d;
162
u8 *pbuf;
163
u32 val;
164
u8 ret;
165
166
167
d = (struct dvobj_priv *)p;
168
val = SDIO_ERR_VAL32;
169
_halmac_mac_reg_page0_chk(__func__, d, offset);
170
pbuf = rtw_zmalloc(4);
171
if (!pbuf)
172
return val;
173
174
ret = rtw_sdio_read_cmd53(d, offset, pbuf, 4);
175
if (ret == _FAIL) {
176
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
177
goto exit;
178
}
179
180
val = le32_to_cpu(*(u32 *)pbuf);
181
182
exit:
183
rtw_mfree(pbuf, 4);
184
185
return val;
186
}
187
188
static u8 _halmac_sdio_reg_read_n(void *p, u32 offset, u32 size, u8 *data)
189
{
190
struct dvobj_priv *d = (struct dvobj_priv *)p;
191
u8 *pbuf;
192
u8 ret;
193
u8 rst = RTW_HALMAC_FAIL;
194
u32 sdio_read_size;
195
196
197
if (!data)
198
return rst;
199
200
sdio_read_size = RND4(size);
201
sdio_read_size = rtw_sdio_cmd53_align_size(d, sdio_read_size);
202
203
pbuf = rtw_zmalloc(sdio_read_size);
204
if (!pbuf)
205
return rst;
206
207
ret = rtw_sdio_read_cmd53(d, offset, pbuf, sdio_read_size);
208
if (ret == _FAIL) {
209
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
210
goto exit;
211
}
212
213
_rtw_memcpy(data, pbuf, size);
214
rst = RTW_HALMAC_SUCCESS;
215
exit:
216
rtw_mfree(pbuf, sdio_read_size);
217
218
return rst;
219
}
220
221
static void _halmac_sdio_reg_write_8(void *p, u32 offset, u8 val)
222
{
223
struct dvobj_priv *d;
224
u8 *pbuf;
225
u8 ret;
226
227
228
d = (struct dvobj_priv *)p;
229
_halmac_mac_reg_page0_chk(__func__, d, offset);
230
pbuf = rtw_zmalloc(1);
231
if (!pbuf)
232
return;
233
_rtw_memcpy(pbuf, &val, 1);
234
235
ret = rtw_sdio_write_cmd53(d, offset, pbuf, 1);
236
if (ret == _FAIL)
237
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
238
239
rtw_mfree(pbuf, 1);
240
}
241
242
static void _halmac_sdio_reg_write_16(void *p, u32 offset, u16 val)
243
{
244
struct dvobj_priv *d;
245
u8 *pbuf;
246
u8 ret;
247
248
249
d = (struct dvobj_priv *)p;
250
_halmac_mac_reg_page0_chk(__func__, d, offset);
251
val = cpu_to_le16(val);
252
pbuf = rtw_zmalloc(2);
253
if (!pbuf)
254
return;
255
_rtw_memcpy(pbuf, &val, 2);
256
257
ret = rtw_sdio_write_cmd53(d, offset, pbuf, 2);
258
if (ret == _FAIL)
259
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
260
261
rtw_mfree(pbuf, 2);
262
}
263
264
static void _halmac_sdio_reg_write_32(void *p, u32 offset, u32 val)
265
{
266
struct dvobj_priv *d;
267
u8 *pbuf;
268
u8 ret;
269
270
271
d = (struct dvobj_priv *)p;
272
_halmac_mac_reg_page0_chk(__func__, d, offset);
273
val = cpu_to_le32(val);
274
pbuf = rtw_zmalloc(4);
275
if (!pbuf)
276
return;
277
_rtw_memcpy(pbuf, &val, 4);
278
279
ret = rtw_sdio_write_cmd53(d, offset, pbuf, 4);
280
if (ret == _FAIL)
281
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
282
283
rtw_mfree(pbuf, 4);
284
}
285
286
static u8 _halmac_sdio_read_cia(void *p, u32 offset)
287
{
288
struct dvobj_priv *d;
289
u8 data = 0;
290
u8 ret;
291
292
293
d = (struct dvobj_priv *)p;
294
295
ret = rtw_sdio_f0_read(d, offset, &data, 1);
296
if (ret == _FAIL)
297
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
298
299
return data;
300
}
301
302
#else /* !CONFIG_SDIO_HCI */
303
304
static u8 _halmac_reg_read_8(void *p, u32 offset)
305
{
306
struct dvobj_priv *d;
307
PADAPTER adapter;
308
309
310
d = (struct dvobj_priv *)p;
311
adapter = dvobj_get_primary_adapter(d);
312
313
return _rtw_read8(adapter, offset);
314
}
315
316
static u16 _halmac_reg_read_16(void *p, u32 offset)
317
{
318
struct dvobj_priv *d;
319
PADAPTER adapter;
320
321
322
d = (struct dvobj_priv *)p;
323
adapter = dvobj_get_primary_adapter(d);
324
325
return _rtw_read16(adapter, offset);
326
}
327
328
static u32 _halmac_reg_read_32(void *p, u32 offset)
329
{
330
struct dvobj_priv *d;
331
PADAPTER adapter;
332
333
334
d = (struct dvobj_priv *)p;
335
adapter = dvobj_get_primary_adapter(d);
336
337
return _rtw_read32(adapter, offset);
338
}
339
340
static void _halmac_reg_write_8(void *p, u32 offset, u8 val)
341
{
342
struct dvobj_priv *d;
343
PADAPTER adapter;
344
int err;
345
346
347
d = (struct dvobj_priv *)p;
348
adapter = dvobj_get_primary_adapter(d);
349
350
err = _rtw_write8(adapter, offset, val);
351
if (err == _FAIL)
352
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
353
}
354
355
static void _halmac_reg_write_16(void *p, u32 offset, u16 val)
356
{
357
struct dvobj_priv *d;
358
PADAPTER adapter;
359
int err;
360
361
362
d = (struct dvobj_priv *)p;
363
adapter = dvobj_get_primary_adapter(d);
364
365
err = _rtw_write16(adapter, offset, val);
366
if (err == _FAIL)
367
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
368
}
369
370
static void _halmac_reg_write_32(void *p, u32 offset, u32 val)
371
{
372
struct dvobj_priv *d;
373
PADAPTER adapter;
374
int err;
375
376
377
d = (struct dvobj_priv *)p;
378
adapter = dvobj_get_primary_adapter(d);
379
380
err = _rtw_write32(adapter, offset, val);
381
if (err == _FAIL)
382
RTW_ERR("%s: I/O FAIL!\n", __FUNCTION__);
383
}
384
#endif /* !CONFIG_SDIO_HCI */
385
386
#ifdef DBG_IO
387
static void _halmac_reg_read_monitor(void *p, u32 addr, u32 len, u32 val
388
, const char *caller, const u32 line)
389
{
390
struct dvobj_priv *d = (struct dvobj_priv *)p;
391
_adapter *adapter = dvobj_get_primary_adapter(d);
392
393
dbg_rtw_reg_read_monitor(adapter, addr, len, val, caller, line);
394
}
395
396
static void _halmac_reg_write_monitor(void *p, u32 addr, u32 len, u32 val
397
, const char *caller, const u32 line)
398
{
399
struct dvobj_priv *d = (struct dvobj_priv *)p;
400
_adapter *adapter = dvobj_get_primary_adapter(d);
401
402
dbg_rtw_reg_write_monitor(adapter, addr, len, val, caller, line);
403
}
404
#endif
405
406
static u8 _halmac_mfree(void *p, void *buffer, u32 size)
407
{
408
rtw_mfree(buffer, size);
409
return RTW_HALMAC_SUCCESS;
410
}
411
412
static void *_halmac_malloc(void *p, u32 size)
413
{
414
return rtw_zmalloc(size);
415
}
416
417
static u8 _halmac_memcpy(void *p, void *dest, void *src, u32 size)
418
{
419
_rtw_memcpy(dest, src, size);
420
return RTW_HALMAC_SUCCESS;
421
}
422
423
static u8 _halmac_memset(void *p, void *addr, u8 value, u32 size)
424
{
425
_rtw_memset(addr, value, size);
426
return RTW_HALMAC_SUCCESS;
427
}
428
429
static void _halmac_udelay(void *p, u32 us)
430
{
431
/* Most hardware polling wait time < 50us) */
432
if (us <= 50)
433
rtw_udelay_os(us);
434
else if (us <= 1000)
435
rtw_usleep_os(us);
436
else
437
rtw_msleep_os(RTW_DIV_ROUND_UP(us, 1000));
438
}
439
440
static u8 _halmac_mutex_init(void *p, HALMAC_MUTEX *pMutex)
441
{
442
_rtw_mutex_init(pMutex);
443
return RTW_HALMAC_SUCCESS;
444
}
445
446
static u8 _halmac_mutex_deinit(void *p, HALMAC_MUTEX *pMutex)
447
{
448
_rtw_mutex_free(pMutex);
449
return RTW_HALMAC_SUCCESS;
450
}
451
452
static u8 _halmac_mutex_lock(void *p, HALMAC_MUTEX *pMutex)
453
{
454
int err;
455
456
err = _enter_critical_mutex(pMutex, NULL);
457
if (err)
458
return RTW_HALMAC_FAIL;
459
460
return RTW_HALMAC_SUCCESS;
461
}
462
463
static u8 _halmac_mutex_unlock(void *p, HALMAC_MUTEX *pMutex)
464
{
465
_exit_critical_mutex(pMutex, NULL);
466
return RTW_HALMAC_SUCCESS;
467
}
468
469
#ifndef CONFIG_SDIO_HCI
470
#define DBG_MSG_FILTER
471
#endif
472
473
#ifdef DBG_MSG_FILTER
474
static u8 is_msg_allowed(uint drv_lv, u8 msg_lv)
475
{
476
switch (drv_lv) {
477
case _DRV_NONE_:
478
return _FALSE;
479
480
case _DRV_ALWAYS_:
481
if (msg_lv > HALMAC_DBG_ALWAYS)
482
return _FALSE;
483
break;
484
case _DRV_ERR_:
485
if (msg_lv > HALMAC_DBG_ERR)
486
return _FALSE;
487
break;
488
case _DRV_WARNING_:
489
if (msg_lv > HALMAC_DBG_WARN)
490
return _FALSE;
491
break;
492
case _DRV_INFO_:
493
if (msg_lv >= HALMAC_DBG_TRACE)
494
return _FALSE;
495
break;
496
}
497
498
return _TRUE;
499
}
500
#endif /* DBG_MSG_FILTER */
501
502
static u8 _halmac_msg_print(void *p, u32 msg_type, u8 msg_level, s8 *fmt, ...)
503
{
504
#define MSG_LEN 100
505
va_list args;
506
u8 str[MSG_LEN] = {0};
507
#ifdef DBG_MSG_FILTER
508
uint drv_level = _DRV_NONE_;
509
#endif
510
int err;
511
u8 ret = RTW_HALMAC_SUCCESS;
512
513
514
#ifdef DBG_MSG_FILTER
515
#ifdef CONFIG_RTW_DEBUG
516
drv_level = rtw_drv_log_level;
517
#endif
518
if (is_msg_allowed(drv_level, msg_level) == _FALSE)
519
return ret;
520
#endif
521
522
str[0] = '\n';
523
va_start(args, fmt);
524
err = vsnprintf(str, MSG_LEN, fmt, args);
525
va_end(args);
526
527
/* An output error is encountered */
528
if (err < 0)
529
return RTW_HALMAC_FAIL;
530
/* Output may be truncated due to size limit */
531
if ((err == (MSG_LEN - 1)) && (str[MSG_LEN - 2] != '\n'))
532
ret = RTW_HALMAC_FAIL;
533
534
if (msg_level == HALMAC_DBG_ALWAYS)
535
RTW_PRINT(MSG_PREFIX "%s", str);
536
else if (msg_level <= HALMAC_DBG_ERR)
537
RTW_ERR(MSG_PREFIX "%s", str);
538
else if (msg_level <= HALMAC_DBG_WARN)
539
RTW_WARN(MSG_PREFIX "%s", str);
540
else
541
RTW_DBG(MSG_PREFIX "%s", str);
542
543
return ret;
544
}
545
546
static u8 _halmac_buff_print(void *p, u32 msg_type, u8 msg_level, s8 *buf, u32 size)
547
{
548
if (msg_level <= HALMAC_DBG_WARN)
549
RTW_INFO_DUMP(MSG_PREFIX, buf, size);
550
else
551
RTW_DBG_DUMP(MSG_PREFIX, buf, size);
552
553
return RTW_HALMAC_SUCCESS;
554
}
555
556
557
const char *const RTW_HALMAC_FEATURE_NAME[] = {
558
"HALMAC_FEATURE_CFG_PARA",
559
"HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE",
560
"HALMAC_FEATURE_DUMP_LOGICAL_EFUSE",
561
"HALMAC_FEATURE_DUMP_LOGICAL_EFUSE_MASK",
562
"HALMAC_FEATURE_UPDATE_PACKET",
563
"HALMAC_FEATURE_SEND_SCAN_PACKET",
564
"HALMAC_FEATURE_DROP_SCAN_PACKET",
565
"HALMAC_FEATURE_UPDATE_DATAPACK",
566
"HALMAC_FEATURE_RUN_DATAPACK",
567
"HALMAC_FEATURE_CHANNEL_SWITCH",
568
"HALMAC_FEATURE_IQK",
569
"HALMAC_FEATURE_POWER_TRACKING",
570
"HALMAC_FEATURE_PSD",
571
"HALMAC_FEATURE_FW_SNDING",
572
"HALMAC_FEATURE_ALL"
573
};
574
575
static inline u8 is_valid_id_status(enum halmac_feature_id id, enum halmac_cmd_process_status status)
576
{
577
switch (id) {
578
case HALMAC_FEATURE_CFG_PARA:
579
RTW_DBG("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
580
break;
581
case HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE:
582
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
583
if (HALMAC_CMD_PROCESS_DONE != status)
584
RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
585
__FUNCTION__, id, status);
586
break;
587
case HALMAC_FEATURE_DUMP_LOGICAL_EFUSE:
588
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
589
if (HALMAC_CMD_PROCESS_DONE != status)
590
RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
591
__FUNCTION__, id, status);
592
break;
593
case HALMAC_FEATURE_UPDATE_PACKET:
594
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
595
if (status != HALMAC_CMD_PROCESS_DONE)
596
RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
597
__FUNCTION__, id, status);
598
break;
599
case HALMAC_FEATURE_UPDATE_DATAPACK:
600
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
601
break;
602
case HALMAC_FEATURE_RUN_DATAPACK:
603
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
604
break;
605
case HALMAC_FEATURE_CHANNEL_SWITCH:
606
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
607
if ((status != HALMAC_CMD_PROCESS_DONE) && (status != HALMAC_CMD_PROCESS_RCVD))
608
RTW_INFO("%s: id(%d) unspecified status(%d)!\n",
609
__FUNCTION__, id, status);
610
if (status == HALMAC_CMD_PROCESS_DONE)
611
return _FALSE;
612
break;
613
case HALMAC_FEATURE_IQK:
614
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
615
break;
616
case HALMAC_FEATURE_POWER_TRACKING:
617
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
618
break;
619
case HALMAC_FEATURE_PSD:
620
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
621
break;
622
case HALMAC_FEATURE_FW_SNDING:
623
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
624
break;
625
case HALMAC_FEATURE_ALL:
626
RTW_INFO("%s: %s\n", __FUNCTION__, RTW_HALMAC_FEATURE_NAME[id]);
627
break;
628
default:
629
RTW_ERR("%s: unknown feature id(%d)\n", __FUNCTION__, id);
630
return _FALSE;
631
}
632
633
return _TRUE;
634
}
635
636
static int init_halmac_event_with_waittime(struct dvobj_priv *d, enum halmac_feature_id id, u8 *buf, u32 size, u32 time)
637
{
638
struct submit_ctx *sctx;
639
640
641
if (!d->hmpriv.indicator[id].sctx) {
642
sctx = (struct submit_ctx *)rtw_zmalloc(sizeof(*sctx));
643
if (!sctx)
644
return -1;
645
} else {
646
RTW_WARN("%s: id(%d) sctx is not NULL!!\n", __FUNCTION__, id);
647
sctx = d->hmpriv.indicator[id].sctx;
648
d->hmpriv.indicator[id].sctx = NULL;
649
}
650
651
rtw_sctx_init(sctx, time);
652
d->hmpriv.indicator[id].buffer = buf;
653
d->hmpriv.indicator[id].buf_size = size;
654
d->hmpriv.indicator[id].ret_size = 0;
655
d->hmpriv.indicator[id].status = 0;
656
/* fill sctx at least to sure other variables are all ready! */
657
d->hmpriv.indicator[id].sctx = sctx;
658
659
return 0;
660
}
661
662
static inline int init_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id, u8 *buf, u32 size)
663
{
664
return init_halmac_event_with_waittime(d, id, buf, size, DEFAULT_INDICATOR_TIMELMT);
665
}
666
667
static void free_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id)
668
{
669
struct submit_ctx *sctx;
670
671
672
if (!d->hmpriv.indicator[id].sctx)
673
return;
674
675
sctx = d->hmpriv.indicator[id].sctx;
676
d->hmpriv.indicator[id].sctx = NULL;
677
rtw_mfree((u8 *)sctx, sizeof(*sctx));
678
}
679
680
static int wait_halmac_event(struct dvobj_priv *d, enum halmac_feature_id id)
681
{
682
struct halmac_adapter *mac;
683
struct halmac_api *api;
684
struct submit_ctx *sctx;
685
int ret;
686
687
688
sctx = d->hmpriv.indicator[id].sctx;
689
if (!sctx)
690
return -1;
691
692
ret = rtw_sctx_wait(sctx, RTW_HALMAC_FEATURE_NAME[id]);
693
free_halmac_event(d, id);
694
if (_SUCCESS == ret)
695
return 0;
696
697
/* timeout! We have to reset halmac state */
698
RTW_ERR("%s: Wait id(%d, %s) TIMEOUT! Reset HALMAC state!\n",
699
__FUNCTION__, id, RTW_HALMAC_FEATURE_NAME[id]);
700
mac = dvobj_to_halmac(d);
701
api = HALMAC_GET_API(mac);
702
api->halmac_reset_feature(mac, id);
703
704
return -1;
705
}
706
707
/*
708
* Return:
709
* Always return RTW_HALMAC_SUCCESS, HALMAC don't care the return value.
710
*/
711
static u8 _halmac_event_indication(void *p, enum halmac_feature_id feature_id, enum halmac_cmd_process_status process_status, u8 *buf, u32 size)
712
{
713
struct dvobj_priv *d;
714
PADAPTER adapter;
715
PHAL_DATA_TYPE hal;
716
struct halmac_indicator *tbl, *indicator;
717
struct submit_ctx *sctx;
718
u32 cpsz;
719
u8 ret;
720
721
722
d = (struct dvobj_priv *)p;
723
adapter = dvobj_get_primary_adapter(d);
724
hal = GET_HAL_DATA(adapter);
725
tbl = d->hmpriv.indicator;
726
727
/* Filter(Skip) middle status indication */
728
ret = is_valid_id_status(feature_id, process_status);
729
if (_FALSE == ret)
730
goto exit;
731
732
indicator = &tbl[feature_id];
733
indicator->status = process_status;
734
indicator->ret_size = size;
735
if (!indicator->sctx) {
736
RTW_WARN("%s: No feature id(%d, %s) waiting!!\n", __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]);
737
goto exit;
738
}
739
sctx = indicator->sctx;
740
741
if (HALMAC_CMD_PROCESS_ERROR == process_status) {
742
RTW_ERR("%s: Something wrong id(%d, %s)!!\n", __FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]);
743
rtw_sctx_done_err(&sctx, RTW_SCTX_DONE_UNKNOWN);
744
goto exit;
745
}
746
747
if (size > indicator->buf_size) {
748
RTW_WARN("%s: id(%d, %s) buffer is not enough(%d<%d), data will be truncated!\n",
749
__FUNCTION__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id], indicator->buf_size, size);
750
cpsz = indicator->buf_size;
751
} else {
752
cpsz = size;
753
}
754
if (cpsz && indicator->buffer)
755
_rtw_memcpy(indicator->buffer, buf, cpsz);
756
757
rtw_sctx_done(&sctx);
758
759
exit:
760
return RTW_HALMAC_SUCCESS;
761
}
762
763
struct halmac_platform_api rtw_halmac_platform_api = {
764
/* R/W register */
765
#ifdef CONFIG_SDIO_HCI
766
.SDIO_CMD52_READ = _halmac_sdio_cmd52_read,
767
.SDIO_CMD53_READ_8 = _halmac_sdio_reg_read_8,
768
.SDIO_CMD53_READ_16 = _halmac_sdio_reg_read_16,
769
.SDIO_CMD53_READ_32 = _halmac_sdio_reg_read_32,
770
.SDIO_CMD53_READ_N = _halmac_sdio_reg_read_n,
771
.SDIO_CMD52_WRITE = _halmac_sdio_cmd52_write,
772
.SDIO_CMD53_WRITE_8 = _halmac_sdio_reg_write_8,
773
.SDIO_CMD53_WRITE_16 = _halmac_sdio_reg_write_16,
774
.SDIO_CMD53_WRITE_32 = _halmac_sdio_reg_write_32,
775
.SDIO_CMD52_CIA_READ = _halmac_sdio_read_cia,
776
#endif /* CONFIG_SDIO_HCI */
777
#if defined(CONFIG_USB_HCI) || defined(CONFIG_PCI_HCI)
778
.REG_READ_8 = _halmac_reg_read_8,
779
.REG_READ_16 = _halmac_reg_read_16,
780
.REG_READ_32 = _halmac_reg_read_32,
781
.REG_WRITE_8 = _halmac_reg_write_8,
782
.REG_WRITE_16 = _halmac_reg_write_16,
783
.REG_WRITE_32 = _halmac_reg_write_32,
784
#endif /* CONFIG_USB_HCI || CONFIG_PCI_HCI */
785
786
#ifdef DBG_IO
787
.READ_MONITOR = _halmac_reg_read_monitor,
788
.WRITE_MONITOR = _halmac_reg_write_monitor,
789
#endif
790
791
/* Write data */
792
#if 0
793
/* impletement in HAL-IC level */
794
.SEND_RSVD_PAGE = sdio_write_data_rsvd_page,
795
.SEND_H2C_PKT = sdio_write_data_h2c,
796
#endif
797
/* Memory allocate */
798
.RTL_FREE = _halmac_mfree,
799
.RTL_MALLOC = _halmac_malloc,
800
.RTL_MEMCPY = _halmac_memcpy,
801
.RTL_MEMSET = _halmac_memset,
802
803
/* Sleep */
804
.RTL_DELAY_US = _halmac_udelay,
805
806
/* Process Synchronization */
807
.MUTEX_INIT = _halmac_mutex_init,
808
.MUTEX_DEINIT = _halmac_mutex_deinit,
809
.MUTEX_LOCK = _halmac_mutex_lock,
810
.MUTEX_UNLOCK = _halmac_mutex_unlock,
811
812
.MSG_PRINT = _halmac_msg_print,
813
.BUFF_PRINT = _halmac_buff_print,
814
.EVENT_INDICATION = _halmac_event_indication,
815
};
816
817
u8 rtw_halmac_read8(struct intf_hdl *pintfhdl, u32 addr)
818
{
819
struct halmac_adapter *mac;
820
struct halmac_api *api;
821
822
823
/* WARNING: pintf_dev should not be null! */
824
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
825
api = HALMAC_GET_API(mac);
826
827
return api->halmac_reg_read_8(mac, addr);
828
}
829
830
u16 rtw_halmac_read16(struct intf_hdl *pintfhdl, u32 addr)
831
{
832
struct halmac_adapter *mac;
833
struct halmac_api *api;
834
835
836
/* WARNING: pintf_dev should not be null! */
837
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
838
api = HALMAC_GET_API(mac);
839
840
return api->halmac_reg_read_16(mac, addr);
841
}
842
843
u32 rtw_halmac_read32(struct intf_hdl *pintfhdl, u32 addr)
844
{
845
struct halmac_adapter *mac;
846
struct halmac_api *api;
847
848
849
/* WARNING: pintf_dev should not be null! */
850
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
851
api = HALMAC_GET_API(mac);
852
853
return api->halmac_reg_read_32(mac, addr);
854
}
855
856
static void _read_register(struct dvobj_priv *d, u32 addr, u32 cnt, u8 *buf)
857
{
858
#if 1
859
struct _ADAPTER *a;
860
u32 i, n;
861
u16 val16;
862
u32 val32;
863
864
865
a = dvobj_get_primary_adapter(d);
866
867
i = addr & 0x3;
868
/* Handle address not start from 4 bytes alignment case */
869
if (i) {
870
val32 = cpu_to_le32(rtw_read32(a, addr & ~0x3));
871
n = 4 - i;
872
_rtw_memcpy(buf, ((u8 *)&val32) + i, n);
873
i = n;
874
cnt -= n;
875
}
876
877
while (cnt) {
878
if (cnt >= 4)
879
n = 4;
880
else if (cnt >= 2)
881
n = 2;
882
else
883
n = 1;
884
cnt -= n;
885
886
switch (n) {
887
case 1:
888
buf[i] = rtw_read8(a, addr+i);
889
i++;
890
break;
891
case 2:
892
val16 = cpu_to_le16(rtw_read16(a, addr+i));
893
_rtw_memcpy(&buf[i], &val16, 2);
894
i += 2;
895
break;
896
case 4:
897
val32 = cpu_to_le32(rtw_read32(a, addr+i));
898
_rtw_memcpy(&buf[i], &val32, 4);
899
i += 4;
900
break;
901
}
902
}
903
#else
904
struct _ADAPTER *a;
905
u32 i;
906
907
908
a = dvobj_get_primary_adapter(d);
909
for (i = 0; i < cnt; i++)
910
buf[i] = rtw_read8(a, addr + i);
911
#endif
912
}
913
914
#ifdef CONFIG_SDIO_HCI
915
static int _sdio_read_local(struct dvobj_priv *d, u32 addr, u32 cnt, u8 *buf)
916
{
917
struct halmac_adapter *mac;
918
struct halmac_api *api;
919
enum halmac_ret_status status;
920
921
922
if (buf == NULL)
923
return -1;
924
925
mac = dvobj_to_halmac(d);
926
api = HALMAC_GET_API(mac);
927
928
status = api->halmac_reg_sdio_cmd53_read_n(mac, addr, cnt, buf);
929
if (status != HALMAC_RET_SUCCESS) {
930
RTW_ERR("%s: addr=0x%08x cnt=%d err=%d\n",
931
__FUNCTION__, addr, cnt, status);
932
return -1;
933
}
934
935
return 0;
936
}
937
#endif /* CONFIG_SDIO_HCI */
938
939
void rtw_halmac_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem)
940
{
941
struct dvobj_priv *d;
942
943
944
if (pmem == NULL) {
945
RTW_ERR("pmem is NULL\n");
946
return;
947
}
948
949
d = pintfhdl->pintf_dev;
950
951
#ifdef CONFIG_SDIO_HCI
952
if (addr & 0xFFFF0000) {
953
int err = 0;
954
955
err = _sdio_read_local(d, addr, cnt, pmem);
956
if (!err)
957
return;
958
}
959
#endif /* CONFIG_SDIO_HCI */
960
961
_read_register(d, addr, cnt, pmem);
962
}
963
964
#ifdef CONFIG_SDIO_INDIRECT_ACCESS
965
u8 rtw_halmac_iread8(struct intf_hdl *pintfhdl, u32 addr)
966
{
967
struct halmac_adapter *mac;
968
struct halmac_api *api;
969
970
/* WARNING: pintf_dev should not be null! */
971
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
972
api = HALMAC_GET_API(mac);
973
974
/*return api->halmac_reg_read_indirect_8(mac, addr);*/
975
return api->halmac_reg_read_8(mac, addr);
976
}
977
978
u16 rtw_halmac_iread16(struct intf_hdl *pintfhdl, u32 addr)
979
{
980
struct halmac_adapter *mac;
981
struct halmac_api *api;
982
u16 val16 = 0;
983
984
/* WARNING: pintf_dev should not be null! */
985
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
986
api = HALMAC_GET_API(mac);
987
988
/*return api->halmac_reg_read_indirect_16(mac, addr);*/
989
return api->halmac_reg_read_16(mac, addr);
990
}
991
992
u32 rtw_halmac_iread32(struct intf_hdl *pintfhdl, u32 addr)
993
{
994
struct halmac_adapter *mac;
995
struct halmac_api *api;
996
997
998
/* WARNING: pintf_dev should not be null! */
999
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
1000
api = HALMAC_GET_API(mac);
1001
1002
return api->halmac_reg_read_indirect_32(mac, addr);
1003
}
1004
#endif /* CONFIG_SDIO_INDIRECT_ACCESS */
1005
1006
int rtw_halmac_write8(struct intf_hdl *pintfhdl, u32 addr, u8 value)
1007
{
1008
struct halmac_adapter *mac;
1009
struct halmac_api *api;
1010
enum halmac_ret_status status;
1011
1012
1013
/* WARNING: pintf_dev should not be null! */
1014
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
1015
api = HALMAC_GET_API(mac);
1016
1017
status = api->halmac_reg_write_8(mac, addr, value);
1018
1019
if (status == HALMAC_RET_SUCCESS)
1020
return 0;
1021
1022
return -1;
1023
}
1024
1025
int rtw_halmac_write16(struct intf_hdl *pintfhdl, u32 addr, u16 value)
1026
{
1027
struct halmac_adapter *mac;
1028
struct halmac_api *api;
1029
enum halmac_ret_status status;
1030
1031
1032
/* WARNING: pintf_dev should not be null! */
1033
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
1034
api = HALMAC_GET_API(mac);
1035
1036
status = api->halmac_reg_write_16(mac, addr, value);
1037
1038
if (status == HALMAC_RET_SUCCESS)
1039
return 0;
1040
1041
return -1;
1042
}
1043
1044
int rtw_halmac_write32(struct intf_hdl *pintfhdl, u32 addr, u32 value)
1045
{
1046
struct halmac_adapter *mac;
1047
struct halmac_api *api;
1048
enum halmac_ret_status status;
1049
1050
1051
/* WARNING: pintf_dev should not be null! */
1052
mac = dvobj_to_halmac(pintfhdl->pintf_dev);
1053
api = HALMAC_GET_API(mac);
1054
1055
status = api->halmac_reg_write_32(mac, addr, value);
1056
1057
if (status == HALMAC_RET_SUCCESS)
1058
return 0;
1059
1060
return -1;
1061
}
1062
1063
static int init_write_rsvd_page_size(struct dvobj_priv *d)
1064
{
1065
struct halmac_adapter *mac;
1066
struct halmac_api *api;
1067
u32 size = 0;
1068
struct halmac_ofld_func_info ofld_info;
1069
enum halmac_ret_status status;
1070
int err = 0;
1071
1072
1073
#ifdef CONFIG_USB_HCI
1074
/* for USB do not exceed MAX_CMDBUF_SZ */
1075
size = 0x1000;
1076
#elif defined(CONFIG_PCI_HCI)
1077
size = MAX_CMDBUF_SZ - TXDESC_OFFSET;
1078
#elif defined(CONFIG_SDIO_HCI)
1079
size = 0x7000; /* 28KB */
1080
#else
1081
/* Use HALMAC default setting and don't call any function */
1082
return 0;
1083
#endif
1084
#if 0 /* Fail to pass coverity DEADCODE check */
1085
/* If size==0, use HALMAC default setting and don't call any function */
1086
if (!size)
1087
return 0;
1088
#endif
1089
err = rtw_halmac_set_max_dl_fw_size(d, size);
1090
if (err) {
1091
RTW_ERR("%s: Fail to set max download fw size!\n", __FUNCTION__);
1092
return -1;
1093
}
1094
1095
mac = dvobj_to_halmac(d);
1096
api = HALMAC_GET_API(mac);
1097
1098
_rtw_memset(&ofld_info, 0, sizeof(ofld_info));
1099
ofld_info.halmac_malloc_max_sz = 0xFFFFFFFF;
1100
ofld_info.rsvd_pg_drv_buf_max_sz = size;
1101
status = api->halmac_ofld_func_cfg(mac, &ofld_info);
1102
if (status != HALMAC_RET_SUCCESS) {
1103
RTW_ERR("%s: Fail to config offload parameters!\n", __FUNCTION__);
1104
return -1;
1105
}
1106
1107
return 0;
1108
}
1109
1110
static int init_priv(struct halmacpriv *priv)
1111
{
1112
struct halmac_indicator *indicator;
1113
u32 count, size;
1114
1115
1116
if (priv->indicator)
1117
RTW_WARN("%s: HALMAC private data is not CLEAR!\n", __FUNCTION__);
1118
count = HALMAC_FEATURE_ALL + 1;
1119
size = sizeof(*indicator) * count;
1120
indicator = (struct halmac_indicator *)rtw_zmalloc(size);
1121
if (!indicator)
1122
return -1;
1123
priv->indicator = indicator;
1124
1125
return 0;
1126
}
1127
1128
static void deinit_priv(struct halmacpriv *priv)
1129
{
1130
struct halmac_indicator *indicator;
1131
1132
1133
indicator = priv->indicator;
1134
priv->indicator = NULL;
1135
if (indicator) {
1136
u32 count, size;
1137
1138
count = HALMAC_FEATURE_ALL + 1;
1139
#ifdef CONFIG_RTW_DEBUG
1140
{
1141
struct submit_ctx *sctx;
1142
u32 i;
1143
1144
for (i = 0; i < count; i++) {
1145
if (!indicator[i].sctx)
1146
continue;
1147
1148
RTW_WARN("%s: %s id(%d) sctx still exist!!\n",
1149
__FUNCTION__, RTW_HALMAC_FEATURE_NAME[i], i);
1150
sctx = indicator[i].sctx;
1151
indicator[i].sctx = NULL;
1152
rtw_mfree((u8 *)sctx, sizeof(*sctx));
1153
}
1154
}
1155
#endif /* !CONFIG_RTW_DEBUG */
1156
size = sizeof(*indicator) * count;
1157
rtw_mfree((u8 *)indicator, size);
1158
}
1159
}
1160
1161
#ifdef CONFIG_SDIO_HCI
1162
static enum halmac_sdio_spec_ver _sdio_ver_drv2halmac(struct dvobj_priv *d)
1163
{
1164
bool v3;
1165
enum halmac_sdio_spec_ver ver;
1166
1167
1168
v3 = rtw_is_sdio30(dvobj_get_primary_adapter(d));
1169
if (v3)
1170
ver = HALMAC_SDIO_SPEC_VER_3_00;
1171
else
1172
ver = HALMAC_SDIO_SPEC_VER_2_00;
1173
1174
return ver;
1175
}
1176
#endif /* CONFIG_SDIO_HCI */
1177
1178
void rtw_halmac_get_version(char *str, u32 len)
1179
{
1180
enum halmac_ret_status status;
1181
struct halmac_ver ver;
1182
1183
1184
status = halmac_get_version(&ver);
1185
if (status != HALMAC_RET_SUCCESS)
1186
return;
1187
1188
rtw_sprintf(str, len, "V%d_%02d_%02d",
1189
ver.major_ver, ver.prototype_ver, ver.minor_ver);
1190
}
1191
1192
int rtw_halmac_init_adapter(struct dvobj_priv *d, struct halmac_platform_api *pf_api)
1193
{
1194
struct halmac_adapter *halmac;
1195
struct halmac_api *api;
1196
enum halmac_interface intf;
1197
enum halmac_ret_status status;
1198
int err = 0;
1199
#ifdef CONFIG_SDIO_HCI
1200
struct halmac_sdio_hw_info info;
1201
#endif /* CONFIG_SDIO_HCI */
1202
1203
1204
halmac = dvobj_to_halmac(d);
1205
if (halmac) {
1206
RTW_WARN("%s: initialize already completed!\n", __FUNCTION__);
1207
goto error;
1208
}
1209
1210
err = init_priv(&d->hmpriv);
1211
if (err)
1212
goto error;
1213
1214
#ifdef CONFIG_SDIO_HCI
1215
intf = HALMAC_INTERFACE_SDIO;
1216
#elif defined(CONFIG_USB_HCI)
1217
intf = HALMAC_INTERFACE_USB;
1218
#elif defined(CONFIG_PCI_HCI)
1219
intf = HALMAC_INTERFACE_PCIE;
1220
#else
1221
#warning "INTERFACE(CONFIG_XXX_HCI) not be defined!!"
1222
intf = HALMAC_INTERFACE_UNDEFINE;
1223
#endif
1224
status = halmac_init_adapter(d, pf_api, intf, &halmac, &api);
1225
if (HALMAC_RET_SUCCESS != status) {
1226
RTW_ERR("%s: halmac_init_adapter fail!(status=%d)\n", __FUNCTION__, status);
1227
err = -1;
1228
if (halmac)
1229
goto deinit;
1230
goto free;
1231
}
1232
1233
dvobj_set_halmac(d, halmac);
1234
1235
status = api->halmac_interface_integration_tuning(halmac);
1236
if (status != HALMAC_RET_SUCCESS) {
1237
RTW_ERR("%s: halmac_interface_integration_tuning fail!(status=%d)\n", __FUNCTION__, status);
1238
err = -1;
1239
goto deinit;
1240
}
1241
1242
status = api->halmac_phy_cfg(halmac, HALMAC_INTF_PHY_PLATFORM_ALL);
1243
if (status != HALMAC_RET_SUCCESS) {
1244
RTW_ERR("%s: halmac_phy_cfg fail!(status=%d)\n", __FUNCTION__, status);
1245
err = -1;
1246
goto deinit;
1247
}
1248
1249
init_write_rsvd_page_size(d);
1250
1251
#ifdef CONFIG_SDIO_HCI
1252
_rtw_memset(&info, 0, sizeof(info));
1253
info.spec_ver = _sdio_ver_drv2halmac(d);
1254
/* Convert clock speed unit to MHz from Hz */
1255
info.clock_speed = RTW_DIV_ROUND_UP(rtw_sdio_get_clock(d), 1000000);
1256
info.block_size = rtw_sdio_get_block_size(d);
1257
RTW_DBG("%s: SDIO ver=%u clock=%uMHz blk_size=%u bytes\n",
1258
__FUNCTION__, info.spec_ver+2, info.clock_speed,
1259
info.block_size);
1260
status = api->halmac_sdio_hw_info(halmac, &info);
1261
if (status != HALMAC_RET_SUCCESS) {
1262
RTW_ERR("%s: halmac_sdio_hw_info fail!(status=%d)\n",
1263
__FUNCTION__, status);
1264
err = -1;
1265
goto deinit;
1266
}
1267
#endif /* CONFIG_SDIO_HCI */
1268
1269
return 0;
1270
1271
deinit:
1272
status = halmac_deinit_adapter(halmac);
1273
dvobj_set_halmac(d, NULL);
1274
if (status != HALMAC_RET_SUCCESS)
1275
RTW_ERR("%s: halmac_deinit_adapter fail!(status=%d)\n",
1276
__FUNCTION__, status);
1277
1278
free:
1279
deinit_priv(&d->hmpriv);
1280
1281
error:
1282
return err;
1283
}
1284
1285
int rtw_halmac_deinit_adapter(struct dvobj_priv *d)
1286
{
1287
struct halmac_adapter *halmac;
1288
enum halmac_ret_status status;
1289
int err = 0;
1290
1291
1292
halmac = dvobj_to_halmac(d);
1293
if (halmac) {
1294
status = halmac_deinit_adapter(halmac);
1295
dvobj_set_halmac(d, NULL);
1296
if (status != HALMAC_RET_SUCCESS)
1297
err = -1;
1298
}
1299
1300
deinit_priv(&d->hmpriv);
1301
1302
return err;
1303
}
1304
1305
static inline enum halmac_portid _hw_port_drv2halmac(enum _hw_port hwport)
1306
{
1307
enum halmac_portid port = HALMAC_PORTID_NUM;
1308
1309
1310
switch (hwport) {
1311
case HW_PORT0:
1312
port = HALMAC_PORTID0;
1313
break;
1314
case HW_PORT1:
1315
port = HALMAC_PORTID1;
1316
break;
1317
case HW_PORT2:
1318
port = HALMAC_PORTID2;
1319
break;
1320
case HW_PORT3:
1321
port = HALMAC_PORTID3;
1322
break;
1323
case HW_PORT4:
1324
port = HALMAC_PORTID4;
1325
break;
1326
default:
1327
break;
1328
}
1329
1330
return port;
1331
}
1332
1333
static enum halmac_network_type_select _network_type_drv2halmac(u8 type)
1334
{
1335
enum halmac_network_type_select network = HALMAC_NETWORK_UNDEFINE;
1336
1337
1338
switch (type) {
1339
case _HW_STATE_NOLINK_:
1340
case _HW_STATE_MONITOR_:
1341
network = HALMAC_NETWORK_NO_LINK;
1342
break;
1343
1344
case _HW_STATE_ADHOC_:
1345
network = HALMAC_NETWORK_ADHOC;
1346
break;
1347
1348
case _HW_STATE_STATION_:
1349
network = HALMAC_NETWORK_INFRASTRUCTURE;
1350
break;
1351
1352
case _HW_STATE_AP_:
1353
network = HALMAC_NETWORK_AP;
1354
break;
1355
}
1356
1357
return network;
1358
}
1359
1360
static u8 _network_type_halmac2drv(enum halmac_network_type_select network)
1361
{
1362
u8 type = _HW_STATE_NOLINK_;
1363
1364
1365
switch (network) {
1366
case HALMAC_NETWORK_NO_LINK:
1367
case HALMAC_NETWORK_UNDEFINE:
1368
type = _HW_STATE_NOLINK_;
1369
break;
1370
1371
case HALMAC_NETWORK_ADHOC:
1372
type = _HW_STATE_ADHOC_;
1373
break;
1374
1375
case HALMAC_NETWORK_INFRASTRUCTURE:
1376
type = _HW_STATE_STATION_;
1377
break;
1378
1379
case HALMAC_NETWORK_AP:
1380
type = _HW_STATE_AP_;
1381
break;
1382
}
1383
1384
return type;
1385
}
1386
1387
static void _beacon_ctrl_halmac2drv(struct halmac_bcn_ctrl *ctrl,
1388
struct rtw_halmac_bcn_ctrl *drv_ctrl)
1389
{
1390
drv_ctrl->rx_bssid_fit = ctrl->dis_rx_bssid_fit ? 0 : 1;
1391
drv_ctrl->txbcn_rpt = ctrl->en_txbcn_rpt ? 1 : 0;
1392
drv_ctrl->tsf_update = ctrl->dis_tsf_udt ? 0 : 1;
1393
drv_ctrl->enable_bcn = ctrl->en_bcn ? 1 : 0;
1394
drv_ctrl->rxbcn_rpt = ctrl->en_rxbcn_rpt ? 1 : 0;
1395
drv_ctrl->p2p_ctwin = ctrl->en_p2p_ctwin ? 1 : 0;
1396
drv_ctrl->p2p_bcn_area = ctrl->en_p2p_bcn_area ? 1 : 0;
1397
}
1398
1399
static void _beacon_ctrl_drv2halmac(struct rtw_halmac_bcn_ctrl *drv_ctrl,
1400
struct halmac_bcn_ctrl *ctrl)
1401
{
1402
ctrl->dis_rx_bssid_fit = drv_ctrl->rx_bssid_fit ? 0 : 1;
1403
ctrl->en_txbcn_rpt = drv_ctrl->txbcn_rpt ? 1 : 0;
1404
ctrl->dis_tsf_udt = drv_ctrl->tsf_update ? 0 : 1;
1405
ctrl->en_bcn = drv_ctrl->enable_bcn ? 1 : 0;
1406
ctrl->en_rxbcn_rpt = drv_ctrl->rxbcn_rpt ? 1 : 0;
1407
ctrl->en_p2p_ctwin = drv_ctrl->p2p_ctwin ? 1 : 0;
1408
ctrl->en_p2p_bcn_area = drv_ctrl->p2p_bcn_area ? 1 : 0;
1409
}
1410
1411
int rtw_halmac_get_hw_value(struct dvobj_priv *d, enum halmac_hw_id hw_id, void *pvalue)
1412
{
1413
struct halmac_adapter *mac;
1414
struct halmac_api *api;
1415
enum halmac_ret_status status;
1416
1417
1418
mac = dvobj_to_halmac(d);
1419
api = HALMAC_GET_API(mac);
1420
1421
status = api->halmac_get_hw_value(mac, hw_id, pvalue);
1422
if (HALMAC_RET_SUCCESS != status)
1423
return -1;
1424
1425
return 0;
1426
}
1427
1428
/**
1429
* rtw_halmac_get_tx_fifo_size() - TX FIFO size
1430
* @d: struct dvobj_priv*
1431
* @size: TX FIFO size, unit is byte.
1432
*
1433
* Get TX FIFO size(byte) from HALMAC.
1434
*
1435
* Return 0 for OK, otherwise fail.
1436
*/
1437
int rtw_halmac_get_tx_fifo_size(struct dvobj_priv *d, u32 *size)
1438
{
1439
struct halmac_adapter *halmac;
1440
struct halmac_api *api;
1441
enum halmac_ret_status status;
1442
u32 val = 0;
1443
1444
1445
halmac = dvobj_to_halmac(d);
1446
api = HALMAC_GET_API(halmac);
1447
1448
status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFIFO_SIZE, &val);
1449
if (status != HALMAC_RET_SUCCESS)
1450
return -1;
1451
1452
*size = val;
1453
1454
return 0;
1455
}
1456
1457
/**
1458
* rtw_halmac_get_rx_fifo_size() - RX FIFO size
1459
* @d: struct dvobj_priv*
1460
* @size: RX FIFO size, unit is byte
1461
*
1462
* Get RX FIFO size(byte) from HALMAC.
1463
*
1464
* Return 0 for OK, otherwise fail.
1465
*/
1466
int rtw_halmac_get_rx_fifo_size(struct dvobj_priv *d, u32 *size)
1467
{
1468
struct halmac_adapter *halmac;
1469
struct halmac_api *api;
1470
enum halmac_ret_status status;
1471
u32 val = 0;
1472
1473
1474
halmac = dvobj_to_halmac(d);
1475
api = HALMAC_GET_API(halmac);
1476
1477
status = api->halmac_get_hw_value(halmac, HALMAC_HW_RXFIFO_SIZE, &val);
1478
if (status != HALMAC_RET_SUCCESS)
1479
return -1;
1480
1481
*size = val;
1482
1483
return 0;
1484
}
1485
1486
/**
1487
* rtw_halmac_get_rsvd_drv_pg_bndy() - Reserve page boundary of driver
1488
* @d: struct dvobj_priv*
1489
* @size: Page size, unit is byte
1490
*
1491
* Get reserve page boundary of driver from HALMAC.
1492
*
1493
* Return 0 for OK, otherwise fail.
1494
*/
1495
int rtw_halmac_get_rsvd_drv_pg_bndy(struct dvobj_priv *d, u16 *bndy)
1496
{
1497
struct halmac_adapter *halmac;
1498
struct halmac_api *api;
1499
enum halmac_ret_status status;
1500
u16 val = 0;
1501
1502
1503
halmac = dvobj_to_halmac(d);
1504
api = HALMAC_GET_API(halmac);
1505
1506
status = api->halmac_get_hw_value(halmac, HALMAC_HW_RSVD_PG_BNDY, &val);
1507
if (status != HALMAC_RET_SUCCESS)
1508
return -1;
1509
1510
*bndy = val;
1511
1512
return 0;
1513
}
1514
1515
/**
1516
* rtw_halmac_get_page_size() - Page size
1517
* @d: struct dvobj_priv*
1518
* @size: Page size, unit is byte
1519
*
1520
* Get TX/RX page size(byte) from HALMAC.
1521
*
1522
* Return 0 for OK, otherwise fail.
1523
*/
1524
int rtw_halmac_get_page_size(struct dvobj_priv *d, u32 *size)
1525
{
1526
struct halmac_adapter *halmac;
1527
struct halmac_api *api;
1528
enum halmac_ret_status status;
1529
u32 val = 0;
1530
1531
1532
halmac = dvobj_to_halmac(d);
1533
api = HALMAC_GET_API(halmac);
1534
1535
status = api->halmac_get_hw_value(halmac, HALMAC_HW_PAGE_SIZE, &val);
1536
if (status != HALMAC_RET_SUCCESS)
1537
return -1;
1538
1539
*size = val;
1540
1541
return 0;
1542
}
1543
1544
/**
1545
* rtw_halmac_get_tx_agg_align_size() - TX aggregation align size
1546
* @d: struct dvobj_priv*
1547
* @size: TX aggregation align size, unit is byte
1548
*
1549
* Get TX aggregation align size(byte) from HALMAC.
1550
*
1551
* Return 0 for OK, otherwise fail.
1552
*/
1553
int rtw_halmac_get_tx_agg_align_size(struct dvobj_priv *d, u16 *size)
1554
{
1555
struct halmac_adapter *halmac;
1556
struct halmac_api *api;
1557
enum halmac_ret_status status;
1558
u16 val = 0;
1559
1560
1561
halmac = dvobj_to_halmac(d);
1562
api = HALMAC_GET_API(halmac);
1563
1564
status = api->halmac_get_hw_value(halmac, HALMAC_HW_TX_AGG_ALIGN_SIZE, &val);
1565
if (status != HALMAC_RET_SUCCESS)
1566
return -1;
1567
1568
*size = val;
1569
1570
return 0;
1571
}
1572
1573
/**
1574
* rtw_halmac_get_rx_agg_align_size() - RX aggregation align size
1575
* @d: struct dvobj_priv*
1576
* @size: RX aggregation align size, unit is byte
1577
*
1578
* Get RX aggregation align size(byte) from HALMAC.
1579
*
1580
* Return 0 for OK, otherwise fail.
1581
*/
1582
int rtw_halmac_get_rx_agg_align_size(struct dvobj_priv *d, u8 *size)
1583
{
1584
struct halmac_adapter *halmac;
1585
struct halmac_api *api;
1586
enum halmac_ret_status status;
1587
u8 val = 0;
1588
1589
1590
halmac = dvobj_to_halmac(d);
1591
api = HALMAC_GET_API(halmac);
1592
1593
status = api->halmac_get_hw_value(halmac, HALMAC_HW_RX_AGG_ALIGN_SIZE, &val);
1594
if (status != HALMAC_RET_SUCCESS)
1595
return -1;
1596
1597
*size = val;
1598
1599
return 0;
1600
}
1601
1602
/*
1603
* Description:
1604
* Get RX driver info size. RX driver info is a small memory space between
1605
* scriptor and RX payload.
1606
*
1607
* +-------------------------+
1608
* | RX descriptor |
1609
* | usually 24 bytes |
1610
* +-------------------------+
1611
* | RX driver info |
1612
* | depends on driver cfg |
1613
* +-------------------------+
1614
* | RX paylad |
1615
* | |
1616
* +-------------------------+
1617
*
1618
* Parameter:
1619
* d pointer to struct dvobj_priv of driver
1620
* sz rx driver info size in bytes.
1621
*
1622
* Return:
1623
* 0 Success
1624
* other Fail
1625
*/
1626
int rtw_halmac_get_rx_drv_info_sz(struct dvobj_priv *d, u8 *sz)
1627
{
1628
enum halmac_ret_status status;
1629
struct halmac_adapter *halmac = dvobj_to_halmac(d);
1630
struct halmac_api *api = HALMAC_GET_API(halmac);
1631
u8 dw = 0;
1632
1633
status = api->halmac_get_hw_value(halmac, HALMAC_HW_DRV_INFO_SIZE, &dw);
1634
if (status != HALMAC_RET_SUCCESS)
1635
return -1;
1636
1637
*sz = dw * 8;
1638
return 0;
1639
}
1640
1641
/**
1642
* rtw_halmac_get_tx_desc_size() - TX descriptor size
1643
* @d: struct dvobj_priv*
1644
* @size: TX descriptor size, unit is byte.
1645
*
1646
* Get TX descriptor size(byte) from HALMAC.
1647
*
1648
* Return 0 for OK, otherwise fail.
1649
*/
1650
int rtw_halmac_get_tx_desc_size(struct dvobj_priv *d, u32 *size)
1651
{
1652
struct halmac_adapter *halmac;
1653
struct halmac_api *api;
1654
enum halmac_ret_status status;
1655
u32 val = 0;
1656
1657
1658
halmac = dvobj_to_halmac(d);
1659
api = HALMAC_GET_API(halmac);
1660
1661
status = api->halmac_get_hw_value(halmac, HALMAC_HW_TX_DESC_SIZE, &val);
1662
if (status != HALMAC_RET_SUCCESS)
1663
return -1;
1664
1665
*size = val;
1666
1667
return 0;
1668
}
1669
1670
/**
1671
* rtw_halmac_get_rx_desc_size() - RX descriptor size
1672
* @d: struct dvobj_priv*
1673
* @size: RX descriptor size, unit is byte.
1674
*
1675
* Get RX descriptor size(byte) from HALMAC.
1676
*
1677
* Return 0 for OK, otherwise fail.
1678
*/
1679
int rtw_halmac_get_rx_desc_size(struct dvobj_priv *d, u32 *size)
1680
{
1681
struct halmac_adapter *halmac;
1682
struct halmac_api *api;
1683
enum halmac_ret_status status;
1684
u32 val = 0;
1685
1686
1687
halmac = dvobj_to_halmac(d);
1688
api = HALMAC_GET_API(halmac);
1689
1690
status = api->halmac_get_hw_value(halmac, HALMAC_HW_RX_DESC_SIZE, &val);
1691
if (status != HALMAC_RET_SUCCESS)
1692
return -1;
1693
1694
*size = val;
1695
1696
return 0;
1697
}
1698
1699
/**
1700
* rtw_halmac_get_tx_dma_ch_map() - Get TX DMA channel Map for tx desc
1701
* @d: struct dvobj_priv*
1702
* @dma_ch_map: return map of QSEL to DMA channel
1703
* @map_size: size of dma_ch_map
1704
* Suggest size to be last valid QSEL(QSLT_CMD)+1 or full QSLT
1705
* size(0x20)
1706
*
1707
* 8814B would need this to get mapping of QSEL to DMA channel for TX desc.
1708
*
1709
* Return 0 for OK, otherwise fail.
1710
*/
1711
int rtw_halmac_get_tx_dma_ch_map(struct dvobj_priv *d, u8 *dma_ch_map, u8 map_size)
1712
{
1713
struct halmac_adapter *halmac;
1714
struct halmac_api *api;
1715
enum halmac_ret_status status;
1716
struct halmac_rqpn_ch_map map;
1717
enum halmac_dma_ch channel = HALMAC_DMA_CH_UNDEFINE;
1718
u8 qsel;
1719
1720
1721
halmac = dvobj_to_halmac(d);
1722
api = HALMAC_GET_API(halmac);
1723
1724
status = api->halmac_get_hw_value(halmac, HALMAC_HW_RQPN_CH_MAPPING, &map);
1725
if (status != HALMAC_RET_SUCCESS)
1726
return -1;
1727
1728
for (qsel = 0; qsel < map_size; qsel++) {
1729
switch (qsel) {
1730
/*case QSLT_VO:*/
1731
case 0x06:
1732
case 0x07:
1733
channel = map.dma_map_vo;
1734
break;
1735
/*case QSLT_VI:*/
1736
case 0x04:
1737
case 0x05:
1738
channel = map.dma_map_vi;
1739
break;
1740
/*case QSLT_BE:*/
1741
case 0x00:
1742
case 0x03:
1743
channel = map.dma_map_be;
1744
break;
1745
/*case QSLT_BK:*/
1746
case 0x01:
1747
case 0x02:
1748
channel = map.dma_map_bk;
1749
break;
1750
/*case QSLT_BEACON:*/
1751
case 0x10:
1752
channel = HALMAC_DMA_CH_BCN;
1753
break;
1754
/*case QSLT_HIGH:*/
1755
case 0x11:
1756
channel = map.dma_map_hi;
1757
break;
1758
/*case QSLT_MGNT:*/
1759
case 0x12:
1760
channel = map.dma_map_mg;
1761
break;
1762
/*case QSLT_CMD:*/
1763
case 0x13:
1764
channel = HALMAC_DMA_CH_H2C;
1765
break;
1766
default:
1767
/*RTW_ERR("%s: invalid qsel=0x%x\n", __FUNCTION__, qsel);*/
1768
channel = HALMAC_DMA_CH_UNDEFINE;
1769
break;
1770
}
1771
dma_ch_map[qsel] = (u8)channel;
1772
}
1773
1774
return 0;
1775
}
1776
1777
/**
1778
* rtw_halmac_get_fw_max_size() - Firmware MAX size
1779
* @d: struct dvobj_priv*
1780
* @size: MAX Firmware size, unit is byte.
1781
*
1782
* Get Firmware MAX size(byte) from HALMAC.
1783
*
1784
* Return 0 for OK, otherwise fail.
1785
*/
1786
static int rtw_halmac_get_fw_max_size(struct dvobj_priv *d, u32 *size)
1787
{
1788
struct halmac_adapter *halmac;
1789
struct halmac_api *api;
1790
enum halmac_ret_status status;
1791
u32 val = 0;
1792
1793
1794
halmac = dvobj_to_halmac(d);
1795
api = HALMAC_GET_API(halmac);
1796
1797
status = api->halmac_get_hw_value(halmac, HALMAC_HW_FW_MAX_SIZE, &val);
1798
if (status != HALMAC_RET_SUCCESS)
1799
return -1;
1800
1801
*size = val;
1802
1803
return 0;
1804
}
1805
1806
/**
1807
* rtw_halmac_get_ori_h2c_size() - Original H2C MAX size
1808
* @d: struct dvobj_priv*
1809
* @size: H2C MAX size, unit is byte.
1810
*
1811
* Get original H2C MAX size(byte) from HALMAC.
1812
*
1813
* Return 0 for OK, otherwise fail.
1814
*/
1815
int rtw_halmac_get_ori_h2c_size(struct dvobj_priv *d, u32 *size)
1816
{
1817
struct halmac_adapter *halmac;
1818
struct halmac_api *api;
1819
enum halmac_ret_status status;
1820
u32 val = 0;
1821
1822
1823
halmac = dvobj_to_halmac(d);
1824
api = HALMAC_GET_API(halmac);
1825
1826
status = api->halmac_get_hw_value(halmac, HALMAC_HW_ORI_H2C_SIZE, &val);
1827
if (status != HALMAC_RET_SUCCESS)
1828
return -1;
1829
1830
*size = val;
1831
1832
return 0;
1833
}
1834
1835
int rtw_halmac_get_oqt_size(struct dvobj_priv *d, u8 *size)
1836
{
1837
enum halmac_ret_status status;
1838
struct halmac_adapter *halmac;
1839
struct halmac_api *api;
1840
u8 val;
1841
1842
1843
if (!size)
1844
return -1;
1845
1846
halmac = dvobj_to_halmac(d);
1847
api = HALMAC_GET_API(halmac);
1848
1849
status = api->halmac_get_hw_value(halmac, HALMAC_HW_AC_OQT_SIZE, &val);
1850
if (status != HALMAC_RET_SUCCESS)
1851
return -1;
1852
1853
*size = val;
1854
return 0;
1855
}
1856
1857
int rtw_halmac_get_ac_queue_number(struct dvobj_priv *d, u8 *num)
1858
{
1859
enum halmac_ret_status status;
1860
struct halmac_adapter *halmac;
1861
struct halmac_api *api;
1862
u8 val;
1863
1864
1865
if (!num)
1866
return -1;
1867
1868
halmac = dvobj_to_halmac(d);
1869
api = HALMAC_GET_API(halmac);
1870
1871
status = api->halmac_get_hw_value(halmac, HALMAC_HW_AC_QUEUE_NUM, &val);
1872
if (status != HALMAC_RET_SUCCESS)
1873
return -1;
1874
1875
*num = val;
1876
return 0;
1877
}
1878
1879
/**
1880
* rtw_halmac_get_mac_address() - Get MAC address of specific port
1881
* @d: struct dvobj_priv*
1882
* @hwport: port
1883
* @addr: buffer for storing MAC address
1884
*
1885
* Get MAC address of specific port from HALMAC.
1886
*
1887
* Return 0 for OK, otherwise fail.
1888
*/
1889
int rtw_halmac_get_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
1890
{
1891
struct halmac_adapter *halmac;
1892
struct halmac_api *api;
1893
enum halmac_portid port;
1894
union halmac_wlan_addr hwa;
1895
enum halmac_ret_status status;
1896
int err = -1;
1897
1898
1899
if (!addr)
1900
goto out;
1901
1902
halmac = dvobj_to_halmac(d);
1903
api = HALMAC_GET_API(halmac);
1904
port = _hw_port_drv2halmac(hwport);
1905
_rtw_memset(&hwa, 0, sizeof(hwa));
1906
1907
status = api->halmac_get_mac_addr(halmac, port, &hwa);
1908
if (status != HALMAC_RET_SUCCESS)
1909
goto out;
1910
1911
_rtw_memcpy(addr, hwa.addr, 6);
1912
1913
err = 0;
1914
out:
1915
return err;
1916
}
1917
1918
/**
1919
* rtw_halmac_get_network_type() - Get network type of specific port
1920
* @d: struct dvobj_priv*
1921
* @hwport: port
1922
* @type: buffer to put network type (_HW_STATE_*)
1923
*
1924
* Get network type of specific port from HALMAC.
1925
*
1926
* Return 0 for OK, otherwise fail.
1927
*/
1928
int rtw_halmac_get_network_type(struct dvobj_priv *d, enum _hw_port hwport, u8 *type)
1929
{
1930
#if 0
1931
struct halmac_adapter *halmac;
1932
struct halmac_api *api;
1933
enum halmac_portid port;
1934
enum halmac_network_type_select network;
1935
enum halmac_ret_status status;
1936
int err = -1;
1937
1938
1939
halmac = dvobj_to_halmac(d);
1940
api = HALMAC_GET_API(halmac);
1941
port = _hw_port_drv2halmac(hwport);
1942
network = HALMAC_NETWORK_UNDEFINE;
1943
1944
status = api->halmac_get_net_type(halmac, port, &network);
1945
if (status != HALMAC_RET_SUCCESS)
1946
goto out;
1947
1948
*type = _network_type_halmac2drv(network);
1949
1950
err = 0;
1951
out:
1952
return err;
1953
#else
1954
struct _ADAPTER *a;
1955
enum halmac_portid port;
1956
enum halmac_network_type_select network;
1957
u32 val;
1958
int err = -1;
1959
1960
1961
a = dvobj_get_primary_adapter(d);
1962
port = _hw_port_drv2halmac(hwport);
1963
network = HALMAC_NETWORK_UNDEFINE;
1964
1965
switch (port) {
1966
case HALMAC_PORTID0:
1967
val = rtw_read32(a, REG_CR);
1968
network = BIT_GET_NETYPE0(val);
1969
break;
1970
1971
case HALMAC_PORTID1:
1972
val = rtw_read32(a, REG_CR);
1973
network = BIT_GET_NETYPE1(val);
1974
break;
1975
1976
case HALMAC_PORTID2:
1977
val = rtw_read32(a, REG_CR_EXT);
1978
network = BIT_GET_NETYPE2(val);
1979
break;
1980
1981
case HALMAC_PORTID3:
1982
val = rtw_read32(a, REG_CR_EXT);
1983
network = BIT_GET_NETYPE3(val);
1984
break;
1985
1986
case HALMAC_PORTID4:
1987
val = rtw_read32(a, REG_CR_EXT);
1988
network = BIT_GET_NETYPE4(val);
1989
break;
1990
1991
default:
1992
goto out;
1993
}
1994
1995
*type = _network_type_halmac2drv(network);
1996
1997
err = 0;
1998
out:
1999
return err;
2000
#endif
2001
}
2002
2003
/**
2004
* rtw_halmac_get_bcn_ctrl() - Get beacon control setting of specific port
2005
* @d: struct dvobj_priv*
2006
* @hwport: port
2007
* @bcn_ctrl: setting of beacon control
2008
*
2009
* Get beacon control setting of specific port from HALMAC.
2010
*
2011
* Return 0 for OK, otherwise fail.
2012
*/
2013
int rtw_halmac_get_bcn_ctrl(struct dvobj_priv *d, enum _hw_port hwport,
2014
struct rtw_halmac_bcn_ctrl *bcn_ctrl)
2015
{
2016
struct halmac_adapter *halmac;
2017
struct halmac_api *api;
2018
enum halmac_portid port;
2019
struct halmac_bcn_ctrl ctrl;
2020
enum halmac_ret_status status;
2021
int err = -1;
2022
2023
2024
halmac = dvobj_to_halmac(d);
2025
api = HALMAC_GET_API(halmac);
2026
port = _hw_port_drv2halmac(hwport);
2027
_rtw_memset(&ctrl, 0, sizeof(ctrl));
2028
2029
status = api->halmac_rw_bcn_ctrl(halmac, port, 0, &ctrl);
2030
if (status != HALMAC_RET_SUCCESS)
2031
goto out;
2032
_beacon_ctrl_halmac2drv(&ctrl, bcn_ctrl);
2033
2034
err = 0;
2035
out:
2036
return err;
2037
}
2038
2039
/*
2040
* Note:
2041
* When this function return, the register REG_RCR may be changed.
2042
*/
2043
int rtw_halmac_config_rx_info(struct dvobj_priv *d, enum halmac_drv_info info)
2044
{
2045
struct halmac_adapter *halmac;
2046
struct halmac_api *api;
2047
enum halmac_ret_status status;
2048
int err = -1;
2049
2050
2051
halmac = dvobj_to_halmac(d);
2052
api = HALMAC_GET_API(halmac);
2053
2054
status = api->halmac_cfg_drv_info(halmac, info);
2055
if (status != HALMAC_RET_SUCCESS)
2056
goto out;
2057
2058
err = 0;
2059
out:
2060
return err;
2061
}
2062
2063
/**
2064
* rtw_halmac_set_max_dl_fw_size() - Set the MAX download firmware size
2065
* @d: struct dvobj_priv*
2066
* @size: the max download firmware size in one I/O
2067
*
2068
* Set the max download firmware size in one I/O.
2069
* Please also consider the max size of the callback function "SEND_RSVD_PAGE"
2070
* could accept, because download firmware would call "SEND_RSVD_PAGE" to send
2071
* firmware to IC.
2072
*
2073
* If the value of "size" is not even, it would be rounded down to nearest
2074
* even, and 0 and 1 are both invalid value.
2075
*
2076
* Return 0 for setting OK, otherwise fail.
2077
*/
2078
int rtw_halmac_set_max_dl_fw_size(struct dvobj_priv *d, u32 size)
2079
{
2080
struct halmac_adapter *mac;
2081
struct halmac_api *api;
2082
enum halmac_ret_status status;
2083
2084
2085
if (!size || (size == 1))
2086
return -1;
2087
2088
mac = dvobj_to_halmac(d);
2089
if (!mac) {
2090
RTW_ERR("%s: HALMAC is not ready!!\n", __FUNCTION__);
2091
return -1;
2092
}
2093
api = HALMAC_GET_API(mac);
2094
2095
size &= ~1; /* round down to even */
2096
status = api->halmac_cfg_max_dl_size(mac, size);
2097
if (status != HALMAC_RET_SUCCESS) {
2098
RTW_WARN("%s: Fail to cfg_max_dl_size(%d), err=%d!!\n",
2099
__FUNCTION__, size, status);
2100
return -1;
2101
}
2102
2103
return 0;
2104
}
2105
2106
/**
2107
* rtw_halmac_set_mac_address() - Set mac address of specific port
2108
* @d: struct dvobj_priv*
2109
* @hwport: port
2110
* @addr: mac address
2111
*
2112
* Set self mac address of specific port to HALMAC.
2113
*
2114
* Return 0 for OK, otherwise fail.
2115
*/
2116
int rtw_halmac_set_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
2117
{
2118
struct halmac_adapter *halmac;
2119
struct halmac_api *api;
2120
enum halmac_portid port;
2121
union halmac_wlan_addr hwa;
2122
enum halmac_ret_status status;
2123
int err = -1;
2124
2125
2126
halmac = dvobj_to_halmac(d);
2127
api = HALMAC_GET_API(halmac);
2128
2129
port = _hw_port_drv2halmac(hwport);
2130
_rtw_memset(&hwa, 0, sizeof(hwa));
2131
_rtw_memcpy(hwa.addr, addr, 6);
2132
2133
status = api->halmac_cfg_mac_addr(halmac, port, &hwa);
2134
if (status != HALMAC_RET_SUCCESS)
2135
goto out;
2136
2137
err = 0;
2138
out:
2139
return err;
2140
}
2141
2142
/**
2143
* rtw_halmac_set_bssid() - Set BSSID of specific port
2144
* @d: struct dvobj_priv*
2145
* @hwport: port
2146
* @addr: BSSID, mac address of AP
2147
*
2148
* Set BSSID of specific port to HALMAC.
2149
*
2150
* Return 0 for OK, otherwise fail.
2151
*/
2152
int rtw_halmac_set_bssid(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
2153
{
2154
struct halmac_adapter *halmac;
2155
struct halmac_api *api;
2156
enum halmac_portid port;
2157
union halmac_wlan_addr hwa;
2158
enum halmac_ret_status status;
2159
int err = -1;
2160
2161
2162
halmac = dvobj_to_halmac(d);
2163
api = HALMAC_GET_API(halmac);
2164
port = _hw_port_drv2halmac(hwport);
2165
2166
_rtw_memset(&hwa, 0, sizeof(hwa));
2167
_rtw_memcpy(hwa.addr, addr, 6);
2168
status = api->halmac_cfg_bssid(halmac, port, &hwa);
2169
if (status != HALMAC_RET_SUCCESS)
2170
goto out;
2171
2172
err = 0;
2173
out:
2174
return err;
2175
}
2176
2177
/**
2178
* rtw_halmac_set_tx_address() - Set transmitter address of specific port
2179
* @d: struct dvobj_priv*
2180
* @hwport: port
2181
* @addr: transmitter address
2182
*
2183
* Set transmitter address of specific port to HALMAC.
2184
*
2185
* Return 0 for OK, otherwise fail.
2186
*/
2187
int rtw_halmac_set_tx_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr)
2188
{
2189
struct halmac_adapter *halmac;
2190
struct halmac_api *api;
2191
enum halmac_portid port;
2192
union halmac_wlan_addr hwa;
2193
enum halmac_ret_status status;
2194
int err = -1;
2195
2196
2197
halmac = dvobj_to_halmac(d);
2198
api = HALMAC_GET_API(halmac);
2199
port = _hw_port_drv2halmac(hwport);
2200
_rtw_memset(&hwa, 0, sizeof(hwa));
2201
_rtw_memcpy(hwa.addr, addr, 6);
2202
2203
status = api->halmac_cfg_transmitter_addr(halmac, port, &hwa);
2204
if (status != HALMAC_RET_SUCCESS)
2205
goto out;
2206
2207
err = 0;
2208
out:
2209
return err;
2210
}
2211
2212
/**
2213
* rtw_halmac_set_network_type() - Set network type of specific port
2214
* @d: struct dvobj_priv*
2215
* @hwport: port
2216
* @type: network type (_HW_STATE_*)
2217
*
2218
* Set network type of specific port to HALMAC.
2219
*
2220
* Return 0 for OK, otherwise fail.
2221
*/
2222
int rtw_halmac_set_network_type(struct dvobj_priv *d, enum _hw_port hwport, u8 type)
2223
{
2224
struct halmac_adapter *halmac;
2225
struct halmac_api *api;
2226
enum halmac_portid port;
2227
enum halmac_network_type_select network;
2228
enum halmac_ret_status status;
2229
int err = -1;
2230
2231
2232
halmac = dvobj_to_halmac(d);
2233
api = HALMAC_GET_API(halmac);
2234
port = _hw_port_drv2halmac(hwport);
2235
network = _network_type_drv2halmac(type);
2236
2237
status = api->halmac_cfg_net_type(halmac, port, network);
2238
if (status != HALMAC_RET_SUCCESS)
2239
goto out;
2240
2241
err = 0;
2242
out:
2243
return err;
2244
}
2245
2246
/**
2247
* rtw_halmac_reset_tsf() - Reset TSF timer of specific port
2248
* @d: struct dvobj_priv*
2249
* @hwport: port
2250
*
2251
* Notice HALMAC to reset timing synchronization function(TSF) timer of
2252
* specific port.
2253
*
2254
* Return 0 for OK, otherwise fail.
2255
*/
2256
int rtw_halmac_reset_tsf(struct dvobj_priv *d, enum _hw_port hwport)
2257
{
2258
struct halmac_adapter *halmac;
2259
struct halmac_api *api;
2260
enum halmac_portid port;
2261
enum halmac_ret_status status;
2262
int err = -1;
2263
2264
2265
halmac = dvobj_to_halmac(d);
2266
api = HALMAC_GET_API(halmac);
2267
port = _hw_port_drv2halmac(hwport);
2268
2269
status = api->halmac_cfg_tsf_rst(halmac, port);
2270
if (status != HALMAC_RET_SUCCESS)
2271
goto out;
2272
2273
err = 0;
2274
out:
2275
return err;
2276
}
2277
2278
/**
2279
* rtw_halmac_set_bcn_interval() - Set beacon interval of each port
2280
* @d: struct dvobj_priv*
2281
* @hwport: port
2282
* @space: beacon interval, unit is ms
2283
*
2284
* Set beacon interval of specific port to HALMAC.
2285
*
2286
* Return 0 for OK, otherwise fail.
2287
*/
2288
int rtw_halmac_set_bcn_interval(struct dvobj_priv *d, enum _hw_port hwport,
2289
u32 interval)
2290
{
2291
struct halmac_adapter *halmac;
2292
struct halmac_api *api;
2293
enum halmac_portid port;
2294
enum halmac_ret_status status;
2295
int err = -1;
2296
2297
2298
halmac = dvobj_to_halmac(d);
2299
api = HALMAC_GET_API(halmac);
2300
port = _hw_port_drv2halmac(hwport);
2301
2302
status = api->halmac_cfg_bcn_space(halmac, port, interval);
2303
if (status != HALMAC_RET_SUCCESS)
2304
goto out;
2305
2306
err = 0;
2307
out:
2308
return err;
2309
}
2310
2311
/**
2312
* rtw_halmac_set_bcn_ctrl() - Set beacon control setting of each port
2313
* @d: struct dvobj_priv*
2314
* @hwport: port
2315
* @bcn_ctrl: setting of beacon control
2316
*
2317
* Set beacon control setting of specific port to HALMAC.
2318
*
2319
* Return 0 for OK, otherwise fail.
2320
*/
2321
int rtw_halmac_set_bcn_ctrl(struct dvobj_priv *d, enum _hw_port hwport,
2322
struct rtw_halmac_bcn_ctrl *bcn_ctrl)
2323
{
2324
struct halmac_adapter *halmac;
2325
struct halmac_api *api;
2326
enum halmac_portid port;
2327
struct halmac_bcn_ctrl ctrl;
2328
enum halmac_ret_status status;
2329
int err = -1;
2330
2331
2332
halmac = dvobj_to_halmac(d);
2333
api = HALMAC_GET_API(halmac);
2334
port = _hw_port_drv2halmac(hwport);
2335
_rtw_memset(&ctrl, 0, sizeof(ctrl));
2336
_beacon_ctrl_drv2halmac(bcn_ctrl, &ctrl);
2337
2338
status = api->halmac_rw_bcn_ctrl(halmac, port, 1, &ctrl);
2339
if (status != HALMAC_RET_SUCCESS)
2340
goto out;
2341
2342
err = 0;
2343
out:
2344
return err;
2345
}
2346
2347
/**
2348
* rtw_halmac_set_aid() - Set association identifier(AID) of specific port
2349
* @d: struct dvobj_priv*
2350
* @hwport: port
2351
* @aid: Association identifier
2352
*
2353
* Set association identifier(AID) of specific port to HALMAC.
2354
*
2355
* Return 0 for OK, otherwise fail.
2356
*/
2357
int rtw_halmac_set_aid(struct dvobj_priv *d, enum _hw_port hwport, u16 aid)
2358
{
2359
struct halmac_adapter *halmac;
2360
struct halmac_api *api;
2361
enum halmac_portid port;
2362
enum halmac_ret_status status;
2363
int err = -1;
2364
2365
2366
halmac = dvobj_to_halmac(d);
2367
api = HALMAC_GET_API(halmac);
2368
port = _hw_port_drv2halmac(hwport);
2369
2370
#if 0
2371
status = api->halmac_cfg_aid(halmac, port, aid);
2372
if (status != HALMAC_RET_SUCCESS)
2373
goto out;
2374
#else
2375
{
2376
struct _ADAPTER *a;
2377
u32 addr;
2378
u16 val;
2379
2380
a = dvobj_get_primary_adapter(d);
2381
2382
switch (port) {
2383
case 0:
2384
addr = REG_BCN_PSR_RPT;
2385
val = rtw_read16(a, addr);
2386
val = BIT_SET_PS_AID_0(val, aid);
2387
rtw_write16(a, addr, val);
2388
break;
2389
2390
case 1:
2391
addr = REG_BCN_PSR_RPT1;
2392
val = rtw_read16(a, addr);
2393
val = BIT_SET_PS_AID_1(val, aid);
2394
rtw_write16(a, addr, val);
2395
break;
2396
2397
case 2:
2398
addr = REG_BCN_PSR_RPT2;
2399
val = rtw_read16(a, addr);
2400
val = BIT_SET_PS_AID_2(val, aid);
2401
rtw_write16(a, addr, val);
2402
break;
2403
2404
case 3:
2405
addr = REG_BCN_PSR_RPT3;
2406
val = rtw_read16(a, addr);
2407
val = BIT_SET_PS_AID_3(val, aid);
2408
rtw_write16(a, addr, val);
2409
break;
2410
2411
case 4:
2412
addr = REG_BCN_PSR_RPT4;
2413
val = rtw_read16(a, addr);
2414
val = BIT_SET_PS_AID_4(val, aid);
2415
rtw_write16(a, addr, val);
2416
break;
2417
2418
default:
2419
goto out;
2420
}
2421
}
2422
#endif
2423
2424
err = 0;
2425
out:
2426
return err;
2427
}
2428
2429
int rtw_halmac_set_bandwidth(struct dvobj_priv *d, u8 channel, u8 pri_ch_idx, u8 bw)
2430
{
2431
struct halmac_adapter *mac;
2432
struct halmac_api *api;
2433
enum halmac_ret_status status;
2434
2435
2436
mac = dvobj_to_halmac(d);
2437
api = HALMAC_GET_API(mac);
2438
2439
status = api->halmac_cfg_ch_bw(mac, channel, pri_ch_idx, bw);
2440
if (HALMAC_RET_SUCCESS != status)
2441
return -1;
2442
2443
return 0;
2444
}
2445
2446
/**
2447
* rtw_halmac_set_edca() - config edca parameter
2448
* @d: struct dvobj_priv*
2449
* @queue: XMIT_[VO/VI/BE/BK]_QUEUE
2450
* @aifs: Arbitration inter-frame space(AIFS)
2451
* @cw: Contention window(CW)
2452
* @txop: MAX Transmit Opportunity(TXOP)
2453
*
2454
* Return: 0 if process OK, otherwise -1.
2455
*/
2456
int rtw_halmac_set_edca(struct dvobj_priv *d, u8 queue, u8 aifs, u8 cw, u16 txop)
2457
{
2458
struct halmac_adapter *mac;
2459
struct halmac_api *api;
2460
enum halmac_acq_id ac;
2461
struct halmac_edca_para edca;
2462
enum halmac_ret_status status;
2463
2464
2465
mac = dvobj_to_halmac(d);
2466
api = HALMAC_GET_API(mac);
2467
2468
switch (queue) {
2469
case XMIT_VO_QUEUE:
2470
ac = HALMAC_ACQ_ID_VO;
2471
break;
2472
case XMIT_VI_QUEUE:
2473
ac = HALMAC_ACQ_ID_VI;
2474
break;
2475
case XMIT_BE_QUEUE:
2476
ac = HALMAC_ACQ_ID_BE;
2477
break;
2478
case XMIT_BK_QUEUE:
2479
ac = HALMAC_ACQ_ID_BK;
2480
break;
2481
default:
2482
return -1;
2483
}
2484
2485
edca.aifs = aifs;
2486
edca.cw = cw;
2487
edca.txop_limit = txop;
2488
2489
status = api->halmac_cfg_edca_para(mac, ac, &edca);
2490
if (status != HALMAC_RET_SUCCESS)
2491
return -1;
2492
2493
return 0;
2494
}
2495
2496
/**
2497
* rtw_halmac_set_rts_full_bw() - Send RTS to all covered channels
2498
* @d: struct dvobj_priv*
2499
* @enable: _TRUE(enable), _FALSE(disable)
2500
*
2501
* Hradware will duplicate RTS packet to all channels which are covered in used
2502
* bandwidth.
2503
*
2504
* Return 0 if process OK, otherwise -1.
2505
*/
2506
int rtw_halmac_set_rts_full_bw(struct dvobj_priv *d, u8 enable)
2507
{
2508
struct halmac_adapter *mac;
2509
struct halmac_api *api;
2510
enum halmac_ret_status status;
2511
u8 full;
2512
2513
2514
mac = dvobj_to_halmac(d);
2515
api = HALMAC_GET_API(mac);
2516
full = (enable == _TRUE) ? 1 : 0;
2517
2518
status = api->halmac_set_hw_value(mac, HALMAC_HW_RTS_FULL_BW, &full);
2519
if (HALMAC_RET_SUCCESS != status)
2520
return -1;
2521
2522
return 0;
2523
}
2524
2525
#ifdef RTW_HALMAC_DBG_POWER_SWITCH
2526
static void _dump_mac_reg(struct dvobj_priv *d, u32 start, u32 end)
2527
{
2528
struct _ADAPTER *adapter;
2529
int i, j = 1;
2530
2531
2532
adapter = dvobj_get_primary_adapter(d);
2533
for (i = start; i < end; i += 4) {
2534
if (j % 4 == 1)
2535
RTW_PRINT("0x%04x", i);
2536
_RTW_PRINT(" 0x%08x ", rtw_read32(adapter, i));
2537
if ((j++) % 4 == 0)
2538
_RTW_PRINT("\n");
2539
}
2540
}
2541
2542
void dump_dbg_val(struct _ADAPTER *a, u32 reg)
2543
{
2544
u32 v32;
2545
2546
2547
rtw_write8(a, 0x3A, reg);
2548
v32 = rtw_read32(a, 0xC0);
2549
RTW_PRINT("0x3A = %02x, 0xC0 = 0x%08x\n",reg, v32);
2550
}
2551
2552
#ifdef CONFIG_PCI_HCI
2553
static void _dump_pcie_cfg_space(struct dvobj_priv *d)
2554
{
2555
struct _ADAPTER *padapter = dvobj_get_primary_adapter(d);
2556
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
2557
struct pci_dev *pdev = pdvobjpriv->ppcidev;
2558
struct pci_dev *bridge_pdev = pdev->bus->self;
2559
2560
u32 tmp[4] = { 0 };
2561
u32 i, j;
2562
2563
RTW_PRINT("\n***** PCI Device Configuration Space *****\n\n");
2564
2565
for(i = 0; i < 0x100; i += 0x10)
2566
{
2567
for (j = 0 ; j < 4 ; j++)
2568
pci_read_config_dword(pdev, i + j * 4, tmp+j);
2569
2570
RTW_PRINT("%03x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
2571
i, tmp[0] & 0xFF, (tmp[0] >> 8) & 0xFF, (tmp[0] >> 16) & 0xFF, (tmp[0] >> 24) & 0xFF,
2572
tmp[1] & 0xFF, (tmp[1] >> 8) & 0xFF, (tmp[1] >> 16) & 0xFF, (tmp[1] >> 24) & 0xFF,
2573
tmp[2] & 0xFF, (tmp[2] >> 8) & 0xFF, (tmp[2] >> 16) & 0xFF, (tmp[2] >> 24) & 0xFF,
2574
tmp[3] & 0xFF, (tmp[3] >> 8) & 0xFF, (tmp[3] >> 16) & 0xFF, (tmp[3] >> 24) & 0xFF);
2575
}
2576
2577
RTW_PRINT("\n***** PCI Host Device Configuration Space*****\n\n");
2578
2579
for(i = 0; i < 0x100; i += 0x10)
2580
{
2581
for (j = 0 ; j < 4 ; j++)
2582
pci_read_config_dword(bridge_pdev, i + j * 4, tmp+j);
2583
2584
RTW_PRINT("%03x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
2585
i, tmp[0] & 0xFF, (tmp[0] >> 8) & 0xFF, (tmp[0] >> 16) & 0xFF, (tmp[0] >> 24) & 0xFF,
2586
tmp[1] & 0xFF, (tmp[1] >> 8) & 0xFF, (tmp[1] >> 16) & 0xFF, (tmp[1] >> 24) & 0xFF,
2587
tmp[2] & 0xFF, (tmp[2] >> 8) & 0xFF, (tmp[2] >> 16) & 0xFF, (tmp[2] >> 24) & 0xFF,
2588
tmp[3] & 0xFF, (tmp[3] >> 8) & 0xFF, (tmp[3] >> 16) & 0xFF, (tmp[3] >> 24) & 0xFF);
2589
}
2590
}
2591
#endif
2592
2593
static void _dump_mac_reg_for_power_switch(struct dvobj_priv *d,
2594
const char* caller, char* desc)
2595
{
2596
struct _ADAPTER *a;
2597
u8 v8;
2598
2599
2600
RTW_PRINT("%s: %s\n", caller, desc);
2601
RTW_PRINT("======= MAC REG =======\n");
2602
/* page 0/1 */
2603
_dump_mac_reg(d, 0x0, 0x200);
2604
_dump_mac_reg(d, 0x300, 0x400); /* also dump page 3 */
2605
2606
/* dump debug register */
2607
a = dvobj_get_primary_adapter(d);
2608
2609
#ifdef CONFIG_PCI_HCI
2610
_dump_pcie_cfg_space(d);
2611
2612
v8 = rtw_read8(a, 0xF6) | 0x01;
2613
rtw_write8(a, 0xF6, v8);
2614
RTW_PRINT("0xF6 = %02x\n", v8);
2615
2616
dump_dbg_val(a, 0x63);
2617
dump_dbg_val(a, 0x64);
2618
dump_dbg_val(a, 0x68);
2619
dump_dbg_val(a, 0x69);
2620
dump_dbg_val(a, 0x6a);
2621
dump_dbg_val(a, 0x6b);
2622
dump_dbg_val(a, 0x71);
2623
dump_dbg_val(a, 0x72);
2624
#endif
2625
}
2626
2627
static enum halmac_ret_status _power_switch(struct halmac_adapter *halmac,
2628
struct halmac_api *api,
2629
enum halmac_mac_power pwr)
2630
{
2631
enum halmac_ret_status status;
2632
char desc[80] = {0};
2633
2634
2635
rtw_sprintf(desc, 80, "before calling power %s",
2636
(pwr==HALMAC_MAC_POWER_ON)?"on":"off");
2637
_dump_mac_reg_for_power_switch((struct dvobj_priv *)halmac->drv_adapter,
2638
__FUNCTION__, desc);
2639
2640
status = api->halmac_mac_power_switch(halmac, pwr);
2641
RTW_PRINT("%s: status=%d\n", __FUNCTION__, status);
2642
2643
rtw_sprintf(desc, 80, "after calling power %s",
2644
(pwr==HALMAC_MAC_POWER_ON)?"on":"off");
2645
_dump_mac_reg_for_power_switch((struct dvobj_priv *)halmac->drv_adapter,
2646
__FUNCTION__, desc);
2647
2648
return status;
2649
}
2650
#else /* !RTW_HALMAC_DBG_POWER_SWITCH */
2651
#define _power_switch(mac, api, pwr) (api)->halmac_mac_power_switch(mac, pwr)
2652
#endif /* !RTW_HALMAC_DBG_POWER_SWITCH */
2653
2654
/*
2655
* Description:
2656
* Power on device hardware.
2657
* [Notice!] If device's power state is on before,
2658
* it would be power off first and turn on power again.
2659
*
2660
* Return:
2661
* 0 power on success
2662
* -1 power on fail
2663
* -2 power state unchange
2664
*/
2665
int rtw_halmac_poweron(struct dvobj_priv *d)
2666
{
2667
struct halmac_adapter *halmac;
2668
struct halmac_api *api;
2669
enum halmac_ret_status status;
2670
int err = -1;
2671
#if defined(CONFIG_PCI_HCI) && defined(CONFIG_RTL8822B)
2672
struct _ADAPTER *a;
2673
u8 v8;
2674
u32 addr;
2675
2676
a = dvobj_get_primary_adapter(d);
2677
#endif
2678
2679
halmac = dvobj_to_halmac(d);
2680
if (!halmac)
2681
goto out;
2682
2683
api = HALMAC_GET_API(halmac);
2684
2685
status = api->halmac_pre_init_system_cfg(halmac);
2686
if (status != HALMAC_RET_SUCCESS)
2687
goto out;
2688
2689
#ifdef CONFIG_SDIO_HCI
2690
status = api->halmac_sdio_cmd53_4byte(halmac, HALMAC_SDIO_CMD53_4BYTE_MODE_RW);
2691
if (status != HALMAC_RET_SUCCESS)
2692
goto out;
2693
#endif /* CONFIG_SDIO_HCI */
2694
2695
#if defined(CONFIG_PCI_HCI) && defined(CONFIG_RTL8822B)
2696
addr = 0x3F3;
2697
v8 = rtw_read8(a, addr);
2698
RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
2699
/* are we in pcie debug mode? */
2700
if (!(v8 & BIT(2))) {
2701
RTW_PRINT("%s: Enable pcie debug mode\n", __FUNCTION__);
2702
v8 |= BIT(2);
2703
v8 = rtw_write8(a, addr, v8);
2704
}
2705
#endif
2706
2707
status = _power_switch(halmac, api, HALMAC_MAC_POWER_ON);
2708
if (HALMAC_RET_PWR_UNCHANGE == status) {
2709
2710
#if defined(CONFIG_PCI_HCI) && defined(CONFIG_RTL8822B)
2711
addr = 0x3F3;
2712
v8 = rtw_read8(a, addr);
2713
RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
2714
2715
/* are we in pcie debug mode? */
2716
if (!(v8 & BIT(2))) {
2717
RTW_PRINT("%s: Enable pcie debug mode\n", __FUNCTION__);
2718
v8 |= BIT(2);
2719
v8 = rtw_write8(a, addr, v8);
2720
} else if (v8 & BIT(0)) {
2721
/* DMA stuck */
2722
addr = 0x1350;
2723
v8 = rtw_read8(a, addr);
2724
RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
2725
RTW_PRINT("%s: recover DMA stuck\n", __FUNCTION__);
2726
v8 |= BIT(6);
2727
v8 = rtw_write8(a, addr, v8);
2728
RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v8);
2729
}
2730
#endif
2731
/*
2732
* Work around for warm reboot but device not power off,
2733
* but it would also fall into this case when auto power on is enabled.
2734
*/
2735
_power_switch(halmac, api, HALMAC_MAC_POWER_OFF);
2736
status = _power_switch(halmac, api, HALMAC_MAC_POWER_ON);
2737
RTW_WARN("%s: Power state abnormal, try to recover...%s\n",
2738
__FUNCTION__, (HALMAC_RET_SUCCESS == status)?"OK":"FAIL!");
2739
}
2740
if (HALMAC_RET_SUCCESS != status) {
2741
if (HALMAC_RET_PWR_UNCHANGE == status)
2742
err = -2;
2743
goto out;
2744
}
2745
2746
status = api->halmac_init_system_cfg(halmac);
2747
if (status != HALMAC_RET_SUCCESS)
2748
goto out;
2749
2750
err = 0;
2751
out:
2752
return err;
2753
}
2754
2755
/*
2756
* Description:
2757
* Power off device hardware.
2758
*
2759
* Return:
2760
* 0 Power off success
2761
* -1 Power off fail
2762
*/
2763
int rtw_halmac_poweroff(struct dvobj_priv *d)
2764
{
2765
struct halmac_adapter *halmac;
2766
struct halmac_api *api;
2767
enum halmac_ret_status status;
2768
int err = -1;
2769
2770
2771
halmac = dvobj_to_halmac(d);
2772
if (!halmac)
2773
goto out;
2774
2775
api = HALMAC_GET_API(halmac);
2776
2777
status = _power_switch(halmac, api, HALMAC_MAC_POWER_OFF);
2778
if ((HALMAC_RET_SUCCESS != status)
2779
&& (HALMAC_RET_PWR_UNCHANGE != status))
2780
goto out;
2781
2782
err = 0;
2783
out:
2784
return err;
2785
}
2786
2787
#ifdef CONFIG_SUPPORT_TRX_SHARED
2788
static inline enum halmac_rx_fifo_expanding_mode _trx_share_mode_drv2halmac(u8 trx_share_mode)
2789
{
2790
if (0 == trx_share_mode)
2791
return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE;
2792
else if (1 == trx_share_mode)
2793
return HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK;
2794
else if (2 == trx_share_mode)
2795
return HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK;
2796
else if (3 == trx_share_mode)
2797
return HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK;
2798
else
2799
return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE;
2800
}
2801
2802
static enum halmac_rx_fifo_expanding_mode _rtw_get_trx_share_mode(struct _ADAPTER *adapter)
2803
{
2804
struct registry_priv *registry_par = &adapter->registrypriv;
2805
2806
return _trx_share_mode_drv2halmac(registry_par->trx_share_mode);
2807
}
2808
2809
void dump_trx_share_mode(void *sel, struct _ADAPTER *adapter)
2810
{
2811
struct registry_priv *registry_par = &adapter->registrypriv;
2812
u8 mode = _trx_share_mode_drv2halmac(registry_par->trx_share_mode);
2813
2814
if (HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK == mode)
2815
RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_1");
2816
else if (HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK == mode)
2817
RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_2");
2818
else if (HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK == mode)
2819
RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_3");
2820
else
2821
RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "DISABLE");
2822
}
2823
#endif
2824
2825
static enum halmac_drv_rsvd_pg_num _rsvd_page_num_drv2halmac(u16 num)
2826
{
2827
if (num <= 8)
2828
return HALMAC_RSVD_PG_NUM8;
2829
if (num <= 16)
2830
return HALMAC_RSVD_PG_NUM16;
2831
if (num <= 24)
2832
return HALMAC_RSVD_PG_NUM24;
2833
if (num <= 32)
2834
return HALMAC_RSVD_PG_NUM32;
2835
if (num <= 64)
2836
return HALMAC_RSVD_PG_NUM64;
2837
if (num <= 128)
2838
return HALMAC_RSVD_PG_NUM128;
2839
2840
if (num > 256)
2841
RTW_WARN("%s: Fail to allocate RSVD page(%d)!!"
2842
" The MAX RSVD page number is 256...\n",
2843
__FUNCTION__, num);
2844
2845
return HALMAC_RSVD_PG_NUM256;
2846
}
2847
2848
static u16 _rsvd_page_num_halmac2drv(enum halmac_drv_rsvd_pg_num rsvd_page_number)
2849
{
2850
u16 num = 0;
2851
2852
2853
switch (rsvd_page_number) {
2854
case HALMAC_RSVD_PG_NUM8:
2855
num = 8;
2856
break;
2857
2858
case HALMAC_RSVD_PG_NUM16:
2859
num = 16;
2860
break;
2861
2862
case HALMAC_RSVD_PG_NUM24:
2863
num = 24;
2864
break;
2865
2866
case HALMAC_RSVD_PG_NUM32:
2867
num = 32;
2868
break;
2869
2870
case HALMAC_RSVD_PG_NUM64:
2871
num = 64;
2872
break;
2873
2874
case HALMAC_RSVD_PG_NUM128:
2875
num = 128;
2876
break;
2877
2878
case HALMAC_RSVD_PG_NUM256:
2879
num = 256;
2880
break;
2881
}
2882
2883
return num;
2884
}
2885
2886
static enum halmac_trx_mode _choose_trx_mode(struct dvobj_priv *d)
2887
{
2888
PADAPTER p;
2889
2890
2891
p = dvobj_get_primary_adapter(d);
2892
2893
if (p->registrypriv.wifi_spec)
2894
return HALMAC_TRX_MODE_WMM;
2895
2896
#ifdef CONFIG_SUPPORT_TRX_SHARED
2897
if (_rtw_get_trx_share_mode(p))
2898
return HALMAC_TRX_MODE_TRXSHARE;
2899
#endif
2900
2901
return HALMAC_TRX_MODE_NORMAL;
2902
}
2903
2904
static inline enum halmac_rf_type _rf_type_drv2halmac(enum rf_type rf_drv)
2905
{
2906
enum halmac_rf_type rf_mac;
2907
2908
2909
switch (rf_drv) {
2910
case RF_1T1R:
2911
rf_mac = HALMAC_RF_1T1R;
2912
break;
2913
case RF_1T2R:
2914
rf_mac = HALMAC_RF_1T2R;
2915
break;
2916
case RF_2T2R:
2917
rf_mac = HALMAC_RF_2T2R;
2918
break;
2919
case RF_2T3R:
2920
rf_mac = HALMAC_RF_2T3R;
2921
break;
2922
case RF_2T4R:
2923
rf_mac = HALMAC_RF_2T4R;
2924
break;
2925
case RF_3T3R:
2926
rf_mac = HALMAC_RF_3T3R;
2927
break;
2928
case RF_3T4R:
2929
rf_mac = HALMAC_RF_3T4R;
2930
break;
2931
case RF_4T4R:
2932
rf_mac = HALMAC_RF_4T4R;
2933
break;
2934
default:
2935
rf_mac = HALMAC_RF_MAX_TYPE;
2936
RTW_ERR("%s: Invalid RF type(0x%x)!\n", __FUNCTION__, rf_drv);
2937
break;
2938
}
2939
2940
return rf_mac;
2941
}
2942
2943
static inline enum rf_type _rf_type_halmac2drv(enum halmac_rf_type rf_mac)
2944
{
2945
enum rf_type rf_drv;
2946
2947
2948
switch (rf_mac) {
2949
case HALMAC_RF_1T2R:
2950
rf_drv = RF_1T2R;
2951
break;
2952
case HALMAC_RF_2T4R:
2953
rf_drv = RF_2T4R;
2954
break;
2955
case HALMAC_RF_2T2R:
2956
case HALMAC_RF_2T2R_GREEN:
2957
rf_drv = RF_2T2R;
2958
break;
2959
case HALMAC_RF_2T3R:
2960
rf_drv = RF_2T3R;
2961
break;
2962
case HALMAC_RF_1T1R:
2963
rf_drv = RF_1T1R;
2964
break;
2965
case HALMAC_RF_3T3R:
2966
rf_drv = RF_3T3R;
2967
break;
2968
case HALMAC_RF_3T4R:
2969
rf_drv = RF_3T4R;
2970
break;
2971
case HALMAC_RF_4T4R:
2972
rf_drv = RF_4T4R;
2973
break;
2974
default:
2975
rf_drv = RF_TYPE_MAX;
2976
RTW_ERR("%s: Invalid RF type(0x%x)!\n", __FUNCTION__, rf_mac);
2977
break;
2978
}
2979
2980
return rf_drv;
2981
}
2982
2983
static enum odm_cut_version _cut_version_drv2phydm(
2984
enum tag_HAL_Cut_Version_Definition cut_drv)
2985
{
2986
enum odm_cut_version cut_phydm = ODM_CUT_A;
2987
u32 diff;
2988
2989
2990
if (cut_drv > K_CUT_VERSION)
2991
RTW_WARN("%s: unknown cut_ver=%d !!\n", __FUNCTION__, cut_drv);
2992
2993
diff = cut_drv - A_CUT_VERSION;
2994
cut_phydm += diff;
2995
2996
return cut_phydm;
2997
}
2998
2999
static int _send_general_info_by_reg(struct dvobj_priv *d,
3000
struct halmac_general_info *info)
3001
{
3002
struct _ADAPTER *a;
3003
struct hal_com_data *hal;
3004
enum tag_HAL_Cut_Version_Definition cut_drv;
3005
enum rf_type rftype;
3006
enum odm_cut_version cut_phydm;
3007
u8 h2c[RTW_HALMAC_H2C_MAX_SIZE] = {0};
3008
3009
3010
a = dvobj_get_primary_adapter(d);
3011
hal = GET_HAL_DATA(a);
3012
rftype = _rf_type_halmac2drv(info->rf_type);
3013
cut_drv = GET_CVID_CUT_VERSION(hal->version_id);
3014
cut_phydm = _cut_version_drv2phydm(cut_drv);
3015
3016
#define CLASS_GENERAL_INFO_REG 0x02
3017
#define CMD_ID_GENERAL_INFO_REG 0x0C
3018
#define GENERAL_INFO_REG_SET_CMD_ID(buf, v) SET_BITS_TO_LE_4BYTE(buf, 0, 5, v)
3019
#define GENERAL_INFO_REG_SET_CLASS(buf, v) SET_BITS_TO_LE_4BYTE(buf, 5, 3, v)
3020
#define GENERAL_INFO_REG_SET_RFE_TYPE(buf, v) SET_BITS_TO_LE_4BYTE(buf, 8, 8, v)
3021
#define GENERAL_INFO_REG_SET_RF_TYPE(buf, v) SET_BITS_TO_LE_4BYTE(buf, 16, 8, v)
3022
#define GENERAL_INFO_REG_SET_CUT_VERSION(buf, v) SET_BITS_TO_LE_4BYTE(buf, 24, 8, v)
3023
#define GENERAL_INFO_REG_SET_RX_ANT_STATUS(buf, v) SET_BITS_TO_LE_1BYTE(buf+4, 0, 4, v)
3024
#define GENERAL_INFO_REG_SET_TX_ANT_STATUS(buf, v) SET_BITS_TO_LE_1BYTE(buf+4, 4, 4, v)
3025
3026
GENERAL_INFO_REG_SET_CMD_ID(h2c, CMD_ID_GENERAL_INFO_REG);
3027
GENERAL_INFO_REG_SET_CLASS(h2c, CLASS_GENERAL_INFO_REG);
3028
GENERAL_INFO_REG_SET_RFE_TYPE(h2c, info->rfe_type);
3029
GENERAL_INFO_REG_SET_RF_TYPE(h2c, rftype);
3030
GENERAL_INFO_REG_SET_CUT_VERSION(h2c, cut_phydm);
3031
GENERAL_INFO_REG_SET_RX_ANT_STATUS(h2c, info->rx_ant_status);
3032
GENERAL_INFO_REG_SET_TX_ANT_STATUS(h2c, info->tx_ant_status);
3033
3034
return rtw_halmac_send_h2c(d, h2c);
3035
}
3036
3037
static int _send_general_info(struct dvobj_priv *d)
3038
{
3039
struct _ADAPTER *adapter;
3040
struct hal_com_data *hal;
3041
struct halmac_adapter *halmac;
3042
struct halmac_api *api;
3043
struct halmac_general_info info;
3044
enum halmac_ret_status status;
3045
enum rf_type rf = RF_1T1R;
3046
enum bb_path txpath = BB_PATH_A;
3047
enum bb_path rxpath = BB_PATH_A;
3048
int err;
3049
3050
3051
adapter = dvobj_get_primary_adapter(d);
3052
hal = GET_HAL_DATA(adapter);
3053
halmac = dvobj_to_halmac(d);
3054
if (!halmac)
3055
return -1;
3056
api = HALMAC_GET_API(halmac);
3057
3058
_rtw_memset(&info, 0, sizeof(info));
3059
info.rfe_type = (u8)hal->rfe_type;
3060
rtw_hal_get_trx_path(d, &rf, &txpath, &rxpath);
3061
info.rf_type = _rf_type_drv2halmac(rf);
3062
info.tx_ant_status = (u8)txpath;
3063
info.rx_ant_status = (u8)rxpath;
3064
info.ext_pa = 0; /* 2.4G or 5G? format not known */
3065
info.package_type = hal->PackageType;
3066
info.mp_mode = adapter->registrypriv.mp_mode;
3067
3068
status = api->halmac_send_general_info(halmac, &info);
3069
switch (status) {
3070
case HALMAC_RET_SUCCESS:
3071
break;
3072
case HALMAC_RET_NO_DLFW:
3073
RTW_WARN("%s: halmac_send_general_info() fail because fw not dl!\n",
3074
__FUNCTION__);
3075
/* go through */
3076
default:
3077
return -1;
3078
}
3079
3080
err = _send_general_info_by_reg(d, &info);
3081
if (err) {
3082
RTW_ERR("%s: Fail to send general info by register!\n",
3083
__FUNCTION__);
3084
return -1;
3085
}
3086
3087
return 0;
3088
}
3089
3090
static int _cfg_drv_rsvd_pg_num(struct dvobj_priv *d)
3091
{
3092
struct _ADAPTER *a;
3093
struct hal_com_data *hal;
3094
struct halmac_adapter *halmac;
3095
struct halmac_api *api;
3096
enum halmac_drv_rsvd_pg_num rsvd_page_number;
3097
enum halmac_ret_status status;
3098
u16 drv_rsvd_num;
3099
int ret = 0;
3100
3101
3102
a = dvobj_get_primary_adapter(d);
3103
hal = GET_HAL_DATA(a);
3104
halmac = dvobj_to_halmac(d);
3105
api = HALMAC_GET_API(halmac);
3106
3107
drv_rsvd_num = rtw_hal_get_rsvd_page_num(a);
3108
rsvd_page_number = _rsvd_page_num_drv2halmac(drv_rsvd_num);
3109
status = api->halmac_cfg_drv_rsvd_pg_num(halmac, rsvd_page_number);
3110
if (status != HALMAC_RET_SUCCESS) {
3111
ret = -1;
3112
goto exit;
3113
}
3114
hal->drv_rsvd_page_number = _rsvd_page_num_halmac2drv(rsvd_page_number);
3115
3116
exit:
3117
#ifndef DBG_RSVD_PAGE_CFG
3118
if (drv_rsvd_num != _rsvd_page_num_halmac2drv(rsvd_page_number))
3119
#endif
3120
RTW_INFO("%s: request %d pages => halmac %d pages %s\n"
3121
, __FUNCTION__, drv_rsvd_num, _rsvd_page_num_halmac2drv(rsvd_page_number)
3122
, ret ? "fail" : "success");
3123
3124
return ret;
3125
}
3126
3127
static void _debug_dlfw_fail(struct dvobj_priv *d)
3128
{
3129
struct _ADAPTER *a;
3130
u32 addr;
3131
u32 v32, i, n;
3132
3133
3134
a = dvobj_get_primary_adapter(d);
3135
3136
/* read 0x80[15:0], 0x10F8[31:0] once */
3137
addr = 0x80;
3138
v32 = rtw_read16(a, addr);
3139
RTW_PRINT("%s: 0x%X = 0x%04x\n", __FUNCTION__, addr, v32);
3140
3141
addr = 0x10F8;
3142
v32 = rtw_read32(a, addr);
3143
RTW_PRINT("%s: 0x%X = 0x%08x\n", __FUNCTION__, addr, v32);
3144
3145
/* read 0x10FC[31:0], 5 times */
3146
addr = 0x10FC;
3147
n = 5;
3148
for (i = 0; i < n; i++) {
3149
v32 = rtw_read32(a, addr);
3150
RTW_PRINT("%s: 0x%X = 0x%08x (%u/%u)\n",
3151
__FUNCTION__, addr, v32, i, n);
3152
}
3153
3154
/*
3155
* write 0x3A[7:0]=0x28 and 0xF6[7:0]=0x01
3156
* and then read 0xC0[31:0] 5 times
3157
*/
3158
addr = 0x3A;
3159
v32 = 0x28;
3160
rtw_write8(a, addr, (u8)v32);
3161
v32 = rtw_read8(a, addr);
3162
RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v32);
3163
3164
addr = 0xF6;
3165
v32 = 0x1;
3166
rtw_write8(a, addr, (u8)v32);
3167
v32 = rtw_read8(a, addr);
3168
RTW_PRINT("%s: 0x%X = 0x%02x\n", __FUNCTION__, addr, v32);
3169
3170
addr = 0xC0;
3171
n = 5;
3172
for (i = 0; i < n; i++) {
3173
v32 = rtw_read32(a, addr);
3174
RTW_PRINT("%s: 0x%X = 0x%08x (%u/%u)\n",
3175
__FUNCTION__, addr, v32, i, n);
3176
}
3177
3178
mac_reg_dump(NULL, a);
3179
#ifdef CONFIG_SDIO_HCI
3180
RTW_PRINT("======= SDIO Local REG =======\n");
3181
sdio_local_reg_dump(NULL, a);
3182
RTW_PRINT("======= SDIO CCCR REG =======\n");
3183
sd_f0_reg_dump(NULL, a);
3184
#endif /* CONFIG_SDIO_HCI */
3185
3186
/* read 0x80 after 10 secs */
3187
rtw_msleep_os(10000);
3188
addr = 0x80;
3189
v32 = rtw_read16(a, addr);
3190
RTW_PRINT("%s: 0x%X = 0x%04x (after 10 secs)\n",
3191
__FUNCTION__, addr, v32);
3192
}
3193
3194
static enum halmac_ret_status _enter_cpu_sleep_mode(struct dvobj_priv *d)
3195
{
3196
struct hal_com_data *hal;
3197
struct halmac_adapter *mac;
3198
struct halmac_api *api;
3199
3200
3201
hal = GET_HAL_DATA(dvobj_get_primary_adapter(d));
3202
mac = dvobj_to_halmac(d);
3203
api = HALMAC_GET_API(mac);
3204
3205
#ifdef CONFIG_RTL8822B
3206
/* Support after firmware version 21 */
3207
if (hal->firmware_version < 21)
3208
return HALMAC_RET_NOT_SUPPORT;
3209
#elif defined(CONFIG_RTL8821C)
3210
/* Support after firmware version 13.6 or 16 */
3211
if (hal->firmware_version == 13) {
3212
if (hal->firmware_sub_version < 6)
3213
return HALMAC_RET_NOT_SUPPORT;
3214
} else if (hal->firmware_version < 16) {
3215
return HALMAC_RET_NOT_SUPPORT;
3216
}
3217
#endif
3218
3219
return api->halmac_enter_cpu_sleep_mode(mac);
3220
}
3221
3222
/*
3223
* _cpu_sleep() - Let IC CPU enter sleep mode
3224
* @d: struct dvobj_priv*
3225
* @timeout: time limit of wait, unit is ms
3226
* 0 for no limit
3227
*
3228
* Return 0 for CPU in sleep mode, otherwise fail to enter sleep mode.
3229
* Error codes definition are as follow:
3230
* -1 HALMAC enter sleep return fail
3231
* -2 HALMAC get CPU mode return fail
3232
* -110 timeout
3233
*/
3234
static int _cpu_sleep(struct dvobj_priv *d, u32 timeout)
3235
{
3236
struct halmac_adapter *mac;
3237
struct halmac_api *api;
3238
enum halmac_ret_status status;
3239
enum halmac_wlcpu_mode mode = HALMAC_WLCPU_UNDEFINE;
3240
systime start_t;
3241
s32 period = 0;
3242
u32 cnt = 0;
3243
int err = 0;
3244
3245
3246
mac = dvobj_to_halmac(d);
3247
api = HALMAC_GET_API(mac);
3248
3249
start_t = rtw_get_current_time();
3250
3251
status = _enter_cpu_sleep_mode(d);
3252
if (status != HALMAC_RET_SUCCESS) {
3253
if (status != HALMAC_RET_NOT_SUPPORT)
3254
err = -1;
3255
goto exit;
3256
}
3257
3258
do {
3259
cnt++;
3260
3261
mode = HALMAC_WLCPU_UNDEFINE;
3262
status = api->halmac_get_cpu_mode(mac, &mode);
3263
3264
period = rtw_get_passing_time_ms(start_t);
3265
3266
if (status != HALMAC_RET_SUCCESS) {
3267
err = -2;
3268
break;
3269
}
3270
if (mode == HALMAC_WLCPU_SLEEP)
3271
break;
3272
if (period > timeout) {
3273
err = -110;
3274
break;
3275
}
3276
3277
rtw_msleep_os(1);
3278
} while (1);
3279
3280
exit:
3281
if (err)
3282
RTW_ERR("%s: Fail to enter sleep mode! (%d, %d)\n",
3283
__FUNCTION__, status, mode);
3284
3285
RTW_INFO("%s: Cost %dms to polling %u times. (err=%d)\n",
3286
__FUNCTION__, period, cnt, err);
3287
3288
return err;
3289
}
3290
3291
static void _init_trx_cfg_drv(struct dvobj_priv *d)
3292
{
3293
#ifdef CONFIG_PCI_HCI
3294
rtw_hal_irp_reset(dvobj_get_primary_adapter(d));
3295
#endif
3296
}
3297
3298
/*
3299
* Description:
3300
* Downlaod Firmware Flow
3301
*
3302
* Parameters:
3303
* d pointer of struct dvobj_priv
3304
* fw firmware array
3305
* fwsize firmware size
3306
* re_dl re-download firmware or not
3307
* 0: run in init hal flow, not re-download
3308
* 1: it is a stand alone operation, not in init hal flow
3309
*
3310
* Return:
3311
* 0 Success
3312
* others Fail
3313
*/
3314
static int download_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize, u8 re_dl)
3315
{
3316
PHAL_DATA_TYPE hal;
3317
struct halmac_adapter *mac;
3318
struct halmac_api *api;
3319
struct halmac_fw_version fw_vesion;
3320
enum halmac_ret_status status;
3321
int err = 0;
3322
3323
3324
hal = GET_HAL_DATA(dvobj_get_primary_adapter(d));
3325
mac = dvobj_to_halmac(d);
3326
api = HALMAC_GET_API(mac);
3327
3328
if ((!fw) || (!fwsize))
3329
return -1;
3330
3331
/* 1. Driver Stop Tx */
3332
/* ToDo */
3333
3334
/* 2. Driver Check Tx FIFO is empty */
3335
err = rtw_halmac_txfifo_wait_empty(d, 2000); /* wait 2s */
3336
if (err) {
3337
err = -1;
3338
goto resume_tx;
3339
}
3340
3341
/* 3. Config MAX download size */
3342
/*
3343
* Already done in rtw_halmac_init_adapter() or
3344
* somewhere calling rtw_halmac_set_max_dl_fw_size().
3345
*/
3346
3347
if (re_dl) {
3348
/* 4. Enter IC CPU sleep mode */
3349
err = _cpu_sleep(d, 2000);
3350
if (err) {
3351
RTW_ERR("%s: IC CPU fail to enter sleep mode!(%d)\n",
3352
__FUNCTION__, err);
3353
/* skip this error */
3354
err = 0;
3355
}
3356
}
3357
3358
/* 5. Download Firmware */
3359
status = api->halmac_download_firmware(mac, fw, fwsize);
3360
if (status != HALMAC_RET_SUCCESS) {
3361
RTW_ERR("%s: download firmware FAIL! status=0x%02x\n",
3362
__FUNCTION__, status);
3363
_debug_dlfw_fail(d);
3364
err = -1;
3365
goto resume_tx;
3366
}
3367
3368
/* 5.1. (Driver) Reset driver variables if needed */
3369
hal->LastHMEBoxNum = 0;
3370
3371
/* 5.2. (Driver) Get FW version */
3372
status = api->halmac_get_fw_version(mac, &fw_vesion);
3373
if (status == HALMAC_RET_SUCCESS) {
3374
hal->firmware_version = fw_vesion.version;
3375
hal->firmware_sub_version = fw_vesion.sub_version;
3376
hal->firmware_size = fwsize;
3377
}
3378
3379
resume_tx:
3380
/* 6. Driver resume TX if needed */
3381
/* ToDo */
3382
3383
if (err)
3384
goto exit;
3385
3386
if (re_dl) {
3387
enum halmac_trx_mode mode;
3388
3389
/* 7. Change reserved page size */
3390
err = _cfg_drv_rsvd_pg_num(d);
3391
if (err)
3392
return -1;
3393
3394
/* 8. Init TRX Configuration */
3395
mode = _choose_trx_mode(d);
3396
status = api->halmac_init_trx_cfg(mac, mode);
3397
if (HALMAC_RET_SUCCESS != status)
3398
return -1;
3399
_init_trx_cfg_drv(d);
3400
3401
/* 9. Config RX Aggregation */
3402
err = rtw_halmac_rx_agg_switch(d, _TRUE);
3403
if (err)
3404
return -1;
3405
3406
/* 10. Send General Info */
3407
err = _send_general_info(d);
3408
if (err)
3409
return -1;
3410
}
3411
3412
exit:
3413
return err;
3414
}
3415
3416
static int init_mac_flow(struct dvobj_priv *d)
3417
{
3418
PADAPTER p;
3419
struct hal_com_data *hal;
3420
struct halmac_adapter *halmac;
3421
struct halmac_api *api;
3422
enum halmac_drv_rsvd_pg_num rsvd_page_number;
3423
union halmac_wlan_addr hwa;
3424
enum halmac_trx_mode trx_mode;
3425
enum halmac_ret_status status;
3426
u8 drv_rsvd_num;
3427
u8 nettype;
3428
int err, err_ret = -1;
3429
3430
3431
p = dvobj_get_primary_adapter(d);
3432
hal = GET_HAL_DATA(p);
3433
halmac = dvobj_to_halmac(d);
3434
api = HALMAC_GET_API(halmac);
3435
3436
#ifdef CONFIG_SUPPORT_TRX_SHARED
3437
status = api->halmac_cfg_rxff_expand_mode(halmac,
3438
_rtw_get_trx_share_mode(p));
3439
if (status != HALMAC_RET_SUCCESS)
3440
goto out;
3441
#endif
3442
3443
#ifdef DBG_LA_MODE
3444
if (dvobj_to_regsty(d)->la_mode_en) {
3445
status = api->halmac_cfg_la_mode(halmac, HALMAC_LA_MODE_PARTIAL);
3446
if (status != HALMAC_RET_SUCCESS) {
3447
RTW_ERR("%s: Fail to enable LA mode!\n", __FUNCTION__);
3448
goto out;
3449
}
3450
RTW_PRINT("%s: Enable LA mode OK.\n", __FUNCTION__);
3451
}
3452
#endif
3453
3454
err = _cfg_drv_rsvd_pg_num(d);
3455
if (err)
3456
goto out;
3457
3458
#ifdef CONFIG_USB_HCI
3459
status = api->halmac_set_bulkout_num(halmac, d->RtNumOutPipes);
3460
if (status != HALMAC_RET_SUCCESS)
3461
goto out;
3462
#endif /* CONFIG_USB_HCI */
3463
3464
trx_mode = _choose_trx_mode(d);
3465
status = api->halmac_init_mac_cfg(halmac, trx_mode);
3466
if (status != HALMAC_RET_SUCCESS)
3467
goto out;
3468
_init_trx_cfg_drv(d);
3469
3470
err = rtw_halmac_rx_agg_switch(d, _TRUE);
3471
if (err)
3472
goto out;
3473
3474
nettype = dvobj_to_regsty(d)->wireless_mode;
3475
if (is_supported_vht(nettype) == _TRUE)
3476
status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_AC);
3477
else if (is_supported_ht(nettype) == _TRUE)
3478
status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_N);
3479
else if (IsSupportedTxOFDM(nettype) == _TRUE)
3480
status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_G);
3481
else
3482
status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_B);
3483
if (status != HALMAC_RET_SUCCESS)
3484
goto out;
3485
3486
err_ret = 0;
3487
out:
3488
return err_ret;
3489
}
3490
3491
static int _drv_enable_trx(struct dvobj_priv *d)
3492
{
3493
struct _ADAPTER *adapter;
3494
u32 status;
3495
3496
3497
adapter = dvobj_get_primary_adapter(d);
3498
if (adapter->bup == _FALSE) {
3499
#ifdef CONFIG_NEW_NETDEV_HDL
3500
status = rtw_mi_start_drv_threads(adapter);
3501
#else
3502
status = rtw_start_drv_threads(adapter);
3503
#endif
3504
if (status == _FAIL) {
3505
RTW_ERR("%s: Start threads Failed!\n", __FUNCTION__);
3506
return -1;
3507
}
3508
}
3509
3510
rtw_intf_start(adapter);
3511
3512
return 0;
3513
}
3514
3515
/*
3516
* Notices:
3517
* Make sure following information
3518
* 1. GET_HAL_RFPATH
3519
* 2. GET_HAL_DATA(dvobj_get_primary_adapter(d))->rfe_type
3520
* 3. GET_HAL_DATA(dvobj_get_primary_adapter(d))->PackageType
3521
* 4. dvobj_get_primary_adapter(d)->registrypriv.mp_mode
3522
* are all ready before calling this function.
3523
*/
3524
static int _halmac_init_hal(struct dvobj_priv *d, u8 *fw, u32 fwsize)
3525
{
3526
PADAPTER adapter;
3527
struct halmac_adapter *halmac;
3528
struct halmac_api *api;
3529
enum halmac_ret_status status;
3530
u32 ok;
3531
u8 fw_ok = _FALSE;
3532
int err, err_ret = -1;
3533
3534
3535
adapter = dvobj_get_primary_adapter(d);
3536
halmac = dvobj_to_halmac(d);
3537
if (!halmac)
3538
goto out;
3539
api = HALMAC_GET_API(halmac);
3540
3541
/* StatePowerOff */
3542
3543
/* SKIP: halmac_init_adapter (Already done before) */
3544
3545
/* halmac_pre_Init_system_cfg */
3546
/* halmac_mac_power_switch(on) */
3547
/* halmac_Init_system_cfg */
3548
ok = rtw_hal_power_on(adapter);
3549
if (_FAIL == ok)
3550
goto out;
3551
3552
/* StatePowerOn */
3553
3554
/* DownloadFW */
3555
if (fw && fwsize) {
3556
err = download_fw(d, fw, fwsize, 0);
3557
if (err)
3558
goto out;
3559
fw_ok = _TRUE;
3560
}
3561
3562
/* InitMACFlow */
3563
err = init_mac_flow(d);
3564
if (err)
3565
goto out;
3566
3567
/* Driver insert flow: Enable TR/RX */
3568
err = _drv_enable_trx(d);
3569
if (err)
3570
goto out;
3571
3572
/* halmac_send_general_info */
3573
if (_TRUE == fw_ok) {
3574
err = _send_general_info(d);
3575
if (err)
3576
goto out;
3577
}
3578
3579
/* Init Phy parameter-MAC */
3580
ok = rtw_hal_init_mac_register(adapter);
3581
if (_FALSE == ok)
3582
goto out;
3583
3584
/* StateMacInitialized */
3585
3586
/* halmac_cfg_drv_info */
3587
err = rtw_halmac_config_rx_info(d, HALMAC_DRV_INFO_PHY_STATUS);
3588
if (err)
3589
goto out;
3590
3591
/* halmac_set_hw_value(HALMAC_HW_EN_BB_RF) */
3592
/* Init BB, RF */
3593
ok = rtw_hal_init_phy(adapter);
3594
if (_FALSE == ok)
3595
goto out;
3596
3597
status = api->halmac_init_interface_cfg(halmac);
3598
if (status != HALMAC_RET_SUCCESS)
3599
goto out;
3600
3601
/* SKIP: halmac_verify_platform_api */
3602
/* SKIP: halmac_h2c_lb */
3603
3604
/* StateRxIdle */
3605
3606
err_ret = 0;
3607
out:
3608
return err_ret;
3609
}
3610
3611
int rtw_halmac_init_hal(struct dvobj_priv *d)
3612
{
3613
return _halmac_init_hal(d, NULL, 0);
3614
}
3615
3616
/*
3617
* Notices:
3618
* Make sure following information
3619
* 1. GET_HAL_RFPATH
3620
* 2. GET_HAL_DATA(dvobj_get_primary_adapter(d))->rfe_type
3621
* 3. GET_HAL_DATA(dvobj_get_primary_adapter(d))->PackageType
3622
* 4. dvobj_get_primary_adapter(d)->registrypriv.mp_mode
3623
* are all ready before calling this function.
3624
*/
3625
int rtw_halmac_init_hal_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize)
3626
{
3627
return _halmac_init_hal(d, fw, fwsize);
3628
}
3629
3630
/*
3631
* Notices:
3632
* Make sure following information
3633
* 1. GET_HAL_RFPATH
3634
* 2. GET_HAL_DATA(dvobj_get_primary_adapter(d))->rfe_type
3635
* 3. GET_HAL_DATA(dvobj_get_primary_adapter(d))->PackageType
3636
* 4. dvobj_get_primary_adapter(d)->registrypriv.mp_mode
3637
* are all ready before calling this function.
3638
*/
3639
int rtw_halmac_init_hal_fw_file(struct dvobj_priv *d, u8 *fwpath)
3640
{
3641
u8 *fw = NULL;
3642
u32 fwmaxsize = 0, size = 0;
3643
int err = 0;
3644
3645
3646
err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
3647
if (err) {
3648
RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
3649
return -1;
3650
}
3651
3652
fw = rtw_zmalloc(fwmaxsize);
3653
if (!fw)
3654
return -1;
3655
3656
size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
3657
if (!size) {
3658
err = -1;
3659
goto exit;
3660
}
3661
3662
err = _halmac_init_hal(d, fw, size);
3663
3664
exit:
3665
rtw_mfree(fw, fwmaxsize);
3666
/*fw = NULL;*/
3667
3668
return err;
3669
}
3670
3671
int rtw_halmac_deinit_hal(struct dvobj_priv *d)
3672
{
3673
PADAPTER adapter;
3674
struct halmac_adapter *halmac;
3675
struct halmac_api *api;
3676
enum halmac_ret_status status;
3677
int err = -1;
3678
3679
3680
adapter = dvobj_get_primary_adapter(d);
3681
halmac = dvobj_to_halmac(d);
3682
if (!halmac)
3683
goto out;
3684
api = HALMAC_GET_API(halmac);
3685
3686
status = api->halmac_deinit_interface_cfg(halmac);
3687
if (status != HALMAC_RET_SUCCESS)
3688
goto out;
3689
3690
rtw_hal_power_off(adapter);
3691
3692
err = 0;
3693
out:
3694
return err;
3695
}
3696
3697
int rtw_halmac_self_verify(struct dvobj_priv *d)
3698
{
3699
struct halmac_adapter *mac;
3700
struct halmac_api *api;
3701
enum halmac_ret_status status;
3702
int err = -1;
3703
3704
3705
mac = dvobj_to_halmac(d);
3706
api = HALMAC_GET_API(mac);
3707
3708
status = api->halmac_verify_platform_api(mac);
3709
if (status != HALMAC_RET_SUCCESS)
3710
goto out;
3711
3712
status = api->halmac_h2c_lb(mac);
3713
if (status != HALMAC_RET_SUCCESS)
3714
goto out;
3715
3716
err = 0;
3717
out:
3718
return err;
3719
}
3720
3721
static u8 rtw_halmac_txfifo_is_empty(struct dvobj_priv *d)
3722
{
3723
struct halmac_adapter *mac;
3724
struct halmac_api *api;
3725
enum halmac_ret_status status;
3726
u32 chk_num = 10;
3727
u8 rst = _FALSE;
3728
3729
3730
mac = dvobj_to_halmac(d);
3731
api = HALMAC_GET_API(mac);
3732
3733
status = api->halmac_txfifo_is_empty(mac, chk_num);
3734
if (status == HALMAC_RET_SUCCESS)
3735
rst = _TRUE;
3736
3737
return rst;
3738
}
3739
3740
/**
3741
* rtw_halmac_txfifo_wait_empty() - Wait TX FIFO to be emtpy
3742
* @d: struct dvobj_priv*
3743
* @timeout: time limit of wait, unit is ms
3744
* 0 for no limit
3745
*
3746
* Wait TX FIFO to be emtpy.
3747
*
3748
* Return 0 for TX FIFO is empty, otherwise not empty.
3749
*/
3750
int rtw_halmac_txfifo_wait_empty(struct dvobj_priv *d, u32 timeout)
3751
{
3752
struct _ADAPTER *a;
3753
u8 empty = _FALSE;
3754
u32 cnt = 0;
3755
systime start_time = 0;
3756
u32 pass_time; /* ms */
3757
3758
3759
a = dvobj_get_primary_adapter(d);
3760
start_time = rtw_get_current_time();
3761
3762
do {
3763
cnt++;
3764
empty = rtw_halmac_txfifo_is_empty(d);
3765
if (empty == _TRUE)
3766
break;
3767
3768
if (timeout) {
3769
pass_time = rtw_get_passing_time_ms(start_time);
3770
if (pass_time > timeout)
3771
break;
3772
}
3773
if (RTW_CANNOT_IO(a)) {
3774
RTW_WARN("%s: Interrupted by I/O forbiden!\n", __FUNCTION__);
3775
break;
3776
}
3777
3778
rtw_msleep_os(2);
3779
} while (1);
3780
3781
if (empty == _FALSE) {
3782
#ifdef CONFIG_RTW_DEBUG
3783
u16 dbg_reg[] = {0x210, 0x230, 0x234, 0x238, 0x23C, 0x240,
3784
0x418, 0x10FC, 0x10F8, 0x11F4, 0x11F8};
3785
u8 i;
3786
u32 val;
3787
3788
if (!RTW_CANNOT_IO(a)) {
3789
for (i = 0; i < ARRAY_SIZE(dbg_reg); i++) {
3790
val = rtw_read32(a, dbg_reg[i]);
3791
RTW_ERR("REG_%X:0x%08x\n", dbg_reg[i], val);
3792
}
3793
}
3794
#endif /* CONFIG_RTW_DEBUG */
3795
3796
RTW_ERR("%s: Fail to wait txfifo empty!(cnt=%d)\n",
3797
__FUNCTION__, cnt);
3798
return -1;
3799
}
3800
3801
return 0;
3802
}
3803
3804
static enum halmac_dlfw_mem _fw_mem_drv2halmac(enum fw_mem mem, u8 tx_stop)
3805
{
3806
enum halmac_dlfw_mem mem_halmac = HALMAC_DLFW_MEM_UNDEFINE;
3807
3808
3809
switch (mem) {
3810
case FW_EMEM:
3811
if (tx_stop == _FALSE)
3812
mem_halmac = HALMAC_DLFW_MEM_EMEM_RSVD_PG;
3813
else
3814
mem_halmac = HALMAC_DLFW_MEM_EMEM;
3815
break;
3816
3817
case FW_IMEM:
3818
case FW_DMEM:
3819
mem_halmac = HALMAC_DLFW_MEM_UNDEFINE;
3820
break;
3821
}
3822
3823
return mem_halmac;
3824
}
3825
3826
int rtw_halmac_dlfw_mem(struct dvobj_priv *d, u8 *fw, u32 fwsize, enum fw_mem mem)
3827
{
3828
struct halmac_adapter *mac;
3829
struct halmac_api *api;
3830
enum halmac_ret_status status;
3831
enum halmac_dlfw_mem dlfw_mem;
3832
u8 tx_stop = _FALSE;
3833
u32 chk_timeout = 2000; /* unit: ms */
3834
int err = 0;
3835
3836
3837
mac = dvobj_to_halmac(d);
3838
api = HALMAC_GET_API(mac);
3839
3840
if ((!fw) || (!fwsize))
3841
return -1;
3842
3843
#ifndef RTW_HALMAC_DLFW_MEM_NO_STOP_TX
3844
/* 1. Driver Stop Tx */
3845
/* ToDo */
3846
3847
/* 2. Driver Check Tx FIFO is empty */
3848
err = rtw_halmac_txfifo_wait_empty(d, chk_timeout);
3849
if (err)
3850
tx_stop = _FALSE;
3851
else
3852
tx_stop = _TRUE;
3853
#endif /* !RTW_HALMAC_DLFW_MEM_NO_STOP_TX */
3854
3855
/* 3. Download Firmware MEM */
3856
dlfw_mem = _fw_mem_drv2halmac(mem, tx_stop);
3857
if (dlfw_mem == HALMAC_DLFW_MEM_UNDEFINE) {
3858
err = -1;
3859
goto resume_tx;
3860
}
3861
status = api->halmac_free_download_firmware(mac, dlfw_mem, fw, fwsize);
3862
if (status != HALMAC_RET_SUCCESS) {
3863
RTW_ERR("%s: halmac_free_download_firmware fail(err=0x%x)\n",
3864
__FUNCTION__, status);
3865
err = -1;
3866
goto resume_tx;
3867
}
3868
3869
resume_tx:
3870
#ifndef RTW_HALMAC_DLFW_MEM_NO_STOP_TX
3871
/* 4. Driver resume TX if needed */
3872
/* ToDo */
3873
#endif /* !RTW_HALMAC_DLFW_MEM_NO_STOP_TX */
3874
3875
return err;
3876
}
3877
3878
int rtw_halmac_dlfw_mem_from_file(struct dvobj_priv *d, u8 *fwpath, enum fw_mem mem)
3879
{
3880
u8 *fw = NULL;
3881
u32 fwmaxsize = 0, size = 0;
3882
int err = 0;
3883
3884
3885
err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
3886
if (err) {
3887
RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
3888
return -1;
3889
}
3890
3891
fw = rtw_zmalloc(fwmaxsize);
3892
if (!fw)
3893
return -1;
3894
3895
size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
3896
if (size)
3897
err = rtw_halmac_dlfw_mem(d, fw, size, mem);
3898
else
3899
err = -1;
3900
3901
rtw_mfree(fw, fwmaxsize);
3902
/*fw = NULL;*/
3903
3904
return err;
3905
}
3906
3907
/*
3908
* Return:
3909
* 0 Success
3910
* -22 Invalid arguemnt
3911
*/
3912
int rtw_halmac_dlfw(struct dvobj_priv *d, u8 *fw, u32 fwsize)
3913
{
3914
PADAPTER adapter;
3915
enum halmac_ret_status status;
3916
u32 ok;
3917
int err, err_ret = -1;
3918
3919
3920
if (!fw || !fwsize)
3921
return -22;
3922
3923
adapter = dvobj_get_primary_adapter(d);
3924
3925
/* re-download firmware */
3926
if (rtw_is_hw_init_completed(adapter))
3927
return download_fw(d, fw, fwsize, 1);
3928
3929
/* Download firmware before hal init */
3930
/* Power on, download firmware and init mac */
3931
ok = rtw_hal_power_on(adapter);
3932
if (_FAIL == ok)
3933
goto out;
3934
3935
err = download_fw(d, fw, fwsize, 0);
3936
if (err) {
3937
err_ret = err;
3938
goto out;
3939
}
3940
3941
err = init_mac_flow(d);
3942
if (err)
3943
goto out;
3944
3945
err = _send_general_info(d);
3946
if (err)
3947
goto out;
3948
3949
err_ret = 0;
3950
3951
out:
3952
return err_ret;
3953
}
3954
3955
int rtw_halmac_dlfw_from_file(struct dvobj_priv *d, u8 *fwpath)
3956
{
3957
u8 *fw = NULL;
3958
u32 fwmaxsize = 0, size = 0;
3959
int err = 0;
3960
3961
3962
err = rtw_halmac_get_fw_max_size(d, &fwmaxsize);
3963
if (err) {
3964
RTW_ERR("%s: Fail to get Firmware MAX size(err=%d)\n", __FUNCTION__, err);
3965
return -1;
3966
}
3967
3968
fw = rtw_zmalloc(fwmaxsize);
3969
if (!fw)
3970
return -1;
3971
3972
size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize);
3973
if (size)
3974
err = rtw_halmac_dlfw(d, fw, size);
3975
else
3976
err = -1;
3977
3978
rtw_mfree(fw, fwmaxsize);
3979
/*fw = NULL;*/
3980
3981
return err;
3982
}
3983
3984
/*
3985
* Description:
3986
* Power on/off BB/RF domain.
3987
*
3988
* Parameters:
3989
* enable _TRUE/_FALSE for power on/off
3990
*
3991
* Return:
3992
* 0 Success
3993
* others Fail
3994
*/
3995
int rtw_halmac_phy_power_switch(struct dvobj_priv *d, u8 enable)
3996
{
3997
PADAPTER adapter;
3998
struct halmac_adapter *halmac;
3999
struct halmac_api *api;
4000
enum halmac_ret_status status;
4001
u8 on;
4002
4003
4004
adapter = dvobj_get_primary_adapter(d);
4005
halmac = dvobj_to_halmac(d);
4006
if (!halmac)
4007
return -1;
4008
api = HALMAC_GET_API(halmac);
4009
on = (enable == _TRUE) ? 1 : 0;
4010
4011
status = api->halmac_set_hw_value(halmac, HALMAC_HW_EN_BB_RF, &on);
4012
if (status != HALMAC_RET_SUCCESS)
4013
return -1;
4014
4015
return 0;
4016
}
4017
4018
static u8 _is_fw_read_cmd_down(PADAPTER adapter, u8 msgbox_num)
4019
{
4020
u8 read_down = _FALSE;
4021
int retry_cnts = 100;
4022
u8 valid;
4023
4024
do {
4025
valid = rtw_read8(adapter, REG_HMETFR) & BIT(msgbox_num);
4026
if (0 == valid)
4027
read_down = _TRUE;
4028
else
4029
rtw_msleep_os(1);
4030
} while ((!read_down) && (retry_cnts--));
4031
4032
if (_FALSE == read_down)
4033
RTW_WARN("%s, reg_1cc(%x), msg_box(%d)...\n", __func__, rtw_read8(adapter, REG_HMETFR), msgbox_num);
4034
4035
return read_down;
4036
}
4037
4038
/**
4039
* rtw_halmac_send_h2c() - Send H2C to firmware
4040
* @d: struct dvobj_priv*
4041
* @h2c: H2C data buffer, suppose to be 8 bytes
4042
*
4043
* Send H2C to firmware by message box register(0x1D0~0x1D3 & 0x1F0~0x1F3).
4044
*
4045
* Assume firmware be ready to accept H2C here, please check
4046
* (hal->bFWReady == _TRUE) before call this function or make sure firmware is
4047
* ready.
4048
*
4049
* Return: 0 if process OK, otherwise fail to send this H2C.
4050
*/
4051
int rtw_halmac_send_h2c(struct dvobj_priv *d, u8 *h2c)
4052
{
4053
PADAPTER adapter = dvobj_get_primary_adapter(d);
4054
PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter);
4055
u8 h2c_box_num = 0;
4056
u32 msgbox_addr = 0;
4057
u32 msgbox_ex_addr = 0;
4058
u32 h2c_cmd = 0;
4059
u32 h2c_cmd_ex = 0;
4060
int err = -1;
4061
4062
4063
if (!h2c) {
4064
RTW_WARN("%s: pbuf is NULL\n", __FUNCTION__);
4065
return err;
4066
}
4067
4068
if (rtw_is_surprise_removed(adapter)) {
4069
RTW_WARN("%s: surprise removed\n", __FUNCTION__);
4070
return err;
4071
}
4072
4073
_enter_critical_mutex(&d->h2c_fwcmd_mutex, NULL);
4074
4075
/* pay attention to if race condition happened in H2C cmd setting */
4076
h2c_box_num = hal->LastHMEBoxNum;
4077
4078
if (!_is_fw_read_cmd_down(adapter, h2c_box_num)) {
4079
RTW_WARN(" fw read cmd failed...\n");
4080
#ifdef DBG_CONFIG_ERROR_DETECT
4081
hal->srestpriv.self_dect_fw = _TRUE;
4082
hal->srestpriv.self_dect_fw_cnt++;
4083
#endif /* DBG_CONFIG_ERROR_DETECT */
4084
goto exit;
4085
}
4086
4087
/* Write Ext command (byte 4~7) */
4088
msgbox_ex_addr = REG_HMEBOX_E0 + (h2c_box_num * EX_MESSAGE_BOX_SIZE);
4089
_rtw_memcpy((u8 *)(&h2c_cmd_ex), h2c + 4, EX_MESSAGE_BOX_SIZE);
4090
h2c_cmd_ex = le32_to_cpu(h2c_cmd_ex);
4091
rtw_write32(adapter, msgbox_ex_addr, h2c_cmd_ex);
4092
4093
/* Write command (byte 0~3) */
4094
msgbox_addr = REG_HMEBOX0 + (h2c_box_num * MESSAGE_BOX_SIZE);
4095
_rtw_memcpy((u8 *)(&h2c_cmd), h2c, 4);
4096
h2c_cmd = le32_to_cpu(h2c_cmd);
4097
rtw_write32(adapter, msgbox_addr, h2c_cmd);
4098
4099
/* update last msg box number */
4100
hal->LastHMEBoxNum = (h2c_box_num + 1) % MAX_H2C_BOX_NUMS;
4101
err = 0;
4102
4103
#ifdef DBG_H2C_CONTENT
4104
RTW_INFO_DUMP("[H2C] - ", h2c, RTW_HALMAC_H2C_MAX_SIZE);
4105
#endif
4106
exit:
4107
_exit_critical_mutex(&d->h2c_fwcmd_mutex, NULL);
4108
return err;
4109
}
4110
4111
/**
4112
* rtw_halmac_c2h_handle() - Handle C2H for HALMAC
4113
* @d: struct dvobj_priv*
4114
* @c2h: Full C2H packet, including RX description and payload
4115
* @size: Size(byte) of c2h
4116
*
4117
* Send C2H packet to HALMAC to process C2H packets, and the expected C2H ID is
4118
* 0xFF. This function won't have any I/O, so caller doesn't have to call it in
4119
* I/O safe place(ex. command thread).
4120
*
4121
* Please sure doesn't call this function in the same thread as someone is
4122
* waiting HALMAC C2H ack, otherwise there is a deadlock happen.
4123
*
4124
* Return: 0 if process OK, otherwise no action for this C2H.
4125
*/
4126
int rtw_halmac_c2h_handle(struct dvobj_priv *d, u8 *c2h, u32 size)
4127
{
4128
struct halmac_adapter *mac;
4129
struct halmac_api *api;
4130
enum halmac_ret_status status;
4131
4132
4133
mac = dvobj_to_halmac(d);
4134
api = HALMAC_GET_API(mac);
4135
4136
status = api->halmac_get_c2h_info(mac, c2h, size);
4137
if (HALMAC_RET_SUCCESS != status)
4138
return -1;
4139
4140
return 0;
4141
}
4142
4143
int rtw_halmac_get_available_efuse_size(struct dvobj_priv *d, u32 *size)
4144
{
4145
struct halmac_adapter *mac;
4146
struct halmac_api *api;
4147
enum halmac_ret_status status;
4148
u32 val;
4149
4150
4151
mac = dvobj_to_halmac(d);
4152
api = HALMAC_GET_API(mac);
4153
4154
status = api->halmac_get_efuse_available_size(mac, &val);
4155
if (HALMAC_RET_SUCCESS != status)
4156
return -1;
4157
4158
*size = val;
4159
return 0;
4160
}
4161
4162
int rtw_halmac_get_physical_efuse_size(struct dvobj_priv *d, u32 *size)
4163
{
4164
struct halmac_adapter *mac;
4165
struct halmac_api *api;
4166
enum halmac_ret_status status;
4167
u32 val;
4168
4169
4170
mac = dvobj_to_halmac(d);
4171
api = HALMAC_GET_API(mac);
4172
4173
status = api->halmac_get_efuse_size(mac, &val);
4174
if (HALMAC_RET_SUCCESS != status)
4175
return -1;
4176
4177
*size = val;
4178
return 0;
4179
}
4180
4181
int rtw_halmac_read_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size)
4182
{
4183
struct halmac_adapter *mac;
4184
struct halmac_api *api;
4185
enum halmac_ret_status status;
4186
enum halmac_feature_id id;
4187
int ret;
4188
4189
4190
mac = dvobj_to_halmac(d);
4191
api = HALMAC_GET_API(mac);
4192
id = HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE;
4193
4194
ret = init_halmac_event(d, id, map, size);
4195
if (ret)
4196
return -1;
4197
4198
status = api->halmac_dump_efuse_map(mac, HALMAC_EFUSE_R_DRV);
4199
if (HALMAC_RET_SUCCESS != status) {
4200
free_halmac_event(d, id);
4201
return -1;
4202
}
4203
4204
ret = wait_halmac_event(d, id);
4205
if (ret)
4206
return -1;
4207
4208
return 0;
4209
}
4210
4211
int rtw_halmac_read_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
4212
{
4213
struct halmac_adapter *mac;
4214
struct halmac_api *api;
4215
enum halmac_ret_status status;
4216
u8 v;
4217
u32 i;
4218
u8 *efuse = NULL;
4219
u32 size = 0;
4220
int err = 0;
4221
4222
4223
mac = dvobj_to_halmac(d);
4224
api = HALMAC_GET_API(mac);
4225
4226
if (api->halmac_read_efuse) {
4227
for (i = 0; i < cnt; i++) {
4228
status = api->halmac_read_efuse(mac, offset + i, &v);
4229
if (HALMAC_RET_SUCCESS != status)
4230
return -1;
4231
data[i] = v;
4232
}
4233
} else {
4234
err = rtw_halmac_get_physical_efuse_size(d, &size);
4235
if (err)
4236
return -1;
4237
4238
efuse = rtw_zmalloc(size);
4239
if (!efuse)
4240
return -1;
4241
4242
err = rtw_halmac_read_physical_efuse_map(d, efuse, size);
4243
if (err)
4244
err = -1;
4245
else
4246
_rtw_memcpy(data, efuse + offset, cnt);
4247
4248
rtw_mfree(efuse, size);
4249
}
4250
4251
return err;
4252
}
4253
4254
int rtw_halmac_write_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
4255
{
4256
struct halmac_adapter *mac;
4257
struct halmac_api *api;
4258
enum halmac_ret_status status;
4259
u32 i;
4260
4261
4262
mac = dvobj_to_halmac(d);
4263
api = HALMAC_GET_API(mac);
4264
4265
if (api->halmac_write_efuse == NULL)
4266
return -1;
4267
4268
for (i = 0; i < cnt; i++) {
4269
status = api->halmac_write_efuse(mac, offset + i, data[i]);
4270
if (HALMAC_RET_SUCCESS != status)
4271
return -1;
4272
}
4273
4274
return 0;
4275
}
4276
4277
int rtw_halmac_get_logical_efuse_size(struct dvobj_priv *d, u32 *size)
4278
{
4279
struct halmac_adapter *mac;
4280
struct halmac_api *api;
4281
enum halmac_ret_status status;
4282
u32 val;
4283
4284
4285
mac = dvobj_to_halmac(d);
4286
api = HALMAC_GET_API(mac);
4287
4288
status = api->halmac_get_logical_efuse_size(mac, &val);
4289
if (HALMAC_RET_SUCCESS != status)
4290
return -1;
4291
4292
*size = val;
4293
return 0;
4294
}
4295
4296
int rtw_halmac_read_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize)
4297
{
4298
struct halmac_adapter *mac;
4299
struct halmac_api *api;
4300
enum halmac_ret_status status;
4301
enum halmac_feature_id id;
4302
int ret;
4303
4304
4305
mac = dvobj_to_halmac(d);
4306
api = HALMAC_GET_API(mac);
4307
id = HALMAC_FEATURE_DUMP_LOGICAL_EFUSE;
4308
4309
ret = init_halmac_event(d, id, map, size);
4310
if (ret)
4311
return -1;
4312
4313
status = api->halmac_dump_logical_efuse_map(mac, HALMAC_EFUSE_R_DRV);
4314
if (HALMAC_RET_SUCCESS != status) {
4315
free_halmac_event(d, id);
4316
return -1;
4317
}
4318
4319
ret = wait_halmac_event(d, id);
4320
if (ret)
4321
return -1;
4322
4323
if (maskmap && masksize) {
4324
struct halmac_pg_efuse_info pginfo;
4325
4326
pginfo.efuse_map = map;
4327
pginfo.efuse_map_size = size;
4328
pginfo.efuse_mask = maskmap;
4329
pginfo.efuse_mask_size = masksize;
4330
4331
status = api->halmac_mask_logical_efuse(mac, &pginfo);
4332
if (status != HALMAC_RET_SUCCESS)
4333
RTW_WARN("%s: mask logical efuse FAIL!\n", __FUNCTION__);
4334
}
4335
4336
return 0;
4337
}
4338
4339
int rtw_halmac_write_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize)
4340
{
4341
struct halmac_adapter *mac;
4342
struct halmac_api *api;
4343
struct halmac_pg_efuse_info pginfo;
4344
enum halmac_ret_status status;
4345
4346
4347
mac = dvobj_to_halmac(d);
4348
api = HALMAC_GET_API(mac);
4349
4350
pginfo.efuse_map = map;
4351
pginfo.efuse_map_size = size;
4352
pginfo.efuse_mask = maskmap;
4353
pginfo.efuse_mask_size = masksize;
4354
4355
status = api->halmac_pg_efuse_by_map(mac, &pginfo, HALMAC_EFUSE_R_AUTO);
4356
if (HALMAC_RET_SUCCESS != status)
4357
return -1;
4358
4359
return 0;
4360
}
4361
4362
int rtw_halmac_read_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
4363
{
4364
struct halmac_adapter *mac;
4365
struct halmac_api *api;
4366
enum halmac_ret_status status;
4367
u8 v;
4368
u32 i;
4369
4370
4371
mac = dvobj_to_halmac(d);
4372
api = HALMAC_GET_API(mac);
4373
4374
for (i = 0; i < cnt; i++) {
4375
status = api->halmac_read_logical_efuse(mac, offset + i, &v);
4376
if (HALMAC_RET_SUCCESS != status)
4377
return -1;
4378
data[i] = v;
4379
}
4380
4381
return 0;
4382
}
4383
4384
int rtw_halmac_write_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
4385
{
4386
struct halmac_adapter *mac;
4387
struct halmac_api *api;
4388
enum halmac_ret_status status;
4389
u32 i;
4390
4391
4392
mac = dvobj_to_halmac(d);
4393
api = HALMAC_GET_API(mac);
4394
4395
for (i = 0; i < cnt; i++) {
4396
status = api->halmac_write_logical_efuse(mac, offset + i, data[i]);
4397
if (HALMAC_RET_SUCCESS != status)
4398
return -1;
4399
}
4400
4401
return 0;
4402
}
4403
4404
int rtw_halmac_write_bt_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data)
4405
{
4406
struct halmac_adapter *mac;
4407
struct halmac_api *api;
4408
enum halmac_ret_status status;
4409
u32 i;
4410
u8 bank = 1;
4411
4412
4413
mac = dvobj_to_halmac(d);
4414
api = HALMAC_GET_API(mac);
4415
4416
for (i = 0; i < cnt; i++) {
4417
status = api->halmac_write_efuse_bt(mac, offset + i, data[i], bank);
4418
if (HALMAC_RET_SUCCESS != status) {
4419
printk("%s: halmac_write_efuse_bt status = %d\n", __FUNCTION__, status);
4420
return -1;
4421
}
4422
}
4423
printk("%s: halmac_write_efuse_bt status = HALMAC_RET_SUCCESS %d\n", __FUNCTION__, status);
4424
return 0;
4425
}
4426
4427
4428
int rtw_halmac_read_bt_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size)
4429
{
4430
struct halmac_adapter *mac;
4431
struct halmac_api *api;
4432
enum halmac_ret_status status;
4433
int bank = 1;
4434
4435
4436
mac = dvobj_to_halmac(d);
4437
api = HALMAC_GET_API(mac);
4438
4439
status = api->halmac_dump_efuse_map_bt(mac, bank, size, map);
4440
if (HALMAC_RET_SUCCESS != status) {
4441
printk("%s: halmac_dump_efuse_map_bt fail!\n", __FUNCTION__);
4442
return -1;
4443
}
4444
4445
printk("%s: OK!\n", __FUNCTION__);
4446
4447
return 0;
4448
}
4449
4450
static enum hal_fifo_sel _fifo_sel_drv2halmac(u8 fifo_sel)
4451
{
4452
switch (fifo_sel) {
4453
case 0:
4454
return HAL_FIFO_SEL_TX;
4455
case 1:
4456
return HAL_FIFO_SEL_RX;
4457
case 2:
4458
return HAL_FIFO_SEL_RSVD_PAGE;
4459
case 3:
4460
return HAL_FIFO_SEL_REPORT;
4461
case 4:
4462
return HAL_FIFO_SEL_LLT;
4463
case 5:
4464
return HAL_FIFO_SEL_RXBUF_FW;
4465
}
4466
4467
return HAL_FIFO_SEL_RSVD_PAGE;
4468
}
4469
4470
/*#define CONFIG_HALMAC_FIFO_DUMP*/
4471
int rtw_halmac_dump_fifo(struct dvobj_priv *d, u8 fifo_sel, u32 addr, u32 size, u8 *buffer)
4472
{
4473
struct halmac_adapter *mac;
4474
struct halmac_api *api;
4475
enum hal_fifo_sel halmac_fifo_sel;
4476
enum halmac_ret_status status;
4477
u8 *pfifo_map = NULL;
4478
u32 fifo_size = 0;
4479
s8 ret = 0;/* 0:success, -1:error */
4480
u8 mem_created = _FALSE;
4481
4482
4483
mac = dvobj_to_halmac(d);
4484
api = HALMAC_GET_API(mac);
4485
4486
if ((size != 0) && (buffer == NULL))
4487
return -1;
4488
4489
halmac_fifo_sel = _fifo_sel_drv2halmac(fifo_sel);
4490
4491
if ((size) && (buffer)) {
4492
pfifo_map = buffer;
4493
fifo_size = size;
4494
} else {
4495
fifo_size = api->halmac_get_fifo_size(mac, halmac_fifo_sel);
4496
4497
if (fifo_size)
4498
pfifo_map = rtw_zvmalloc(fifo_size);
4499
if (pfifo_map == NULL)
4500
return -1;
4501
mem_created = _TRUE;
4502
}
4503
4504
status = api->halmac_dump_fifo(mac, halmac_fifo_sel, addr, fifo_size, pfifo_map);
4505
if (HALMAC_RET_SUCCESS != status) {
4506
ret = -1;
4507
goto _exit;
4508
}
4509
4510
#ifdef CONFIG_HALMAC_FIFO_DUMP
4511
{
4512
static const char * const fifo_sel_str[] = {
4513
"TX", "RX", "RSVD_PAGE", "REPORT", "LLT", "RXBUF_FW"
4514
};
4515
4516
RTW_INFO("%s FIFO DUMP [start_addr:0x%04x , size:%d]\n", fifo_sel_str[halmac_fifo_sel], addr, fifo_size);
4517
RTW_INFO_DUMP("\n", pfifo_map, fifo_size);
4518
RTW_INFO(" ==================================================\n");
4519
}
4520
#endif /* CONFIG_HALMAC_FIFO_DUMP */
4521
4522
_exit:
4523
if ((mem_created == _TRUE) && pfifo_map)
4524
rtw_vmfree(pfifo_map, fifo_size);
4525
4526
return ret;
4527
}
4528
4529
/*
4530
* rtw_halmac_rx_agg_switch() - Switch RX aggregation function and setting
4531
* @d struct dvobj_priv *
4532
* @enable _FALSE/_TRUE for disable/enable RX aggregation function
4533
*
4534
* This function could help to on/off bus RX aggregation function, and is only
4535
* useful for SDIO and USB interface. Although only "enable" flag is brough in,
4536
* some setting would be taken from other places, and they are from:
4537
* [DMA aggregation]
4538
* struct hal_com_data.rxagg_dma_size
4539
* struct hal_com_data.rxagg_dma_timeout
4540
* [USB aggregation] (only use for USB interface)
4541
* struct hal_com_data.rxagg_usb_size
4542
* struct hal_com_data.rxagg_usb_timeout
4543
* If above values of size and timeout are both 0 means driver would not
4544
* control the threshold setting and leave it to HALMAC handle.
4545
*
4546
* From HALMAC V1_04_04, driver force the size threshold be hard limit, and the
4547
* rx size can not exceed the setting.
4548
*
4549
* Return 0 for success, otherwise fail.
4550
*/
4551
int rtw_halmac_rx_agg_switch(struct dvobj_priv *d, u8 enable)
4552
{
4553
struct _ADAPTER *adapter;
4554
struct hal_com_data *hal;
4555
struct halmac_adapter *halmac;
4556
struct halmac_api *api;
4557
struct halmac_rxagg_cfg rxaggcfg;
4558
enum halmac_ret_status status;
4559
4560
4561
adapter = dvobj_get_primary_adapter(d);
4562
hal = GET_HAL_DATA(adapter);
4563
halmac = dvobj_to_halmac(d);
4564
api = HALMAC_GET_API(halmac);
4565
_rtw_memset((void *)&rxaggcfg, 0, sizeof(rxaggcfg));
4566
rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE;
4567
/*
4568
* Always enable size limit to avoid rx size exceed
4569
* driver defined size.
4570
*/
4571
rxaggcfg.threshold.size_limit_en = 1;
4572
4573
#ifdef RTW_RX_AGGREGATION
4574
if (_TRUE == enable) {
4575
#ifdef CONFIG_SDIO_HCI
4576
rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA;
4577
rxaggcfg.threshold.drv_define = 0;
4578
if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) {
4579
rxaggcfg.threshold.drv_define = 1;
4580
rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout;
4581
rxaggcfg.threshold.size = hal->rxagg_dma_size;
4582
RTW_INFO("%s: RX aggregation threshold: "
4583
"timeout=%u size=%u\n",
4584
__FUNCTION__,
4585
hal->rxagg_dma_timeout,
4586
hal->rxagg_dma_size);
4587
}
4588
#elif defined(CONFIG_USB_HCI)
4589
switch (hal->rxagg_mode) {
4590
case RX_AGG_DISABLE:
4591
rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE;
4592
break;
4593
4594
case RX_AGG_DMA:
4595
rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA;
4596
if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) {
4597
rxaggcfg.threshold.drv_define = 1;
4598
rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout;
4599
rxaggcfg.threshold.size = hal->rxagg_dma_size;
4600
}
4601
break;
4602
4603
case RX_AGG_USB:
4604
case RX_AGG_MIX:
4605
rxaggcfg.mode = HALMAC_RX_AGG_MODE_USB;
4606
if (hal->rxagg_usb_size || hal->rxagg_usb_timeout) {
4607
rxaggcfg.threshold.drv_define = 1;
4608
rxaggcfg.threshold.timeout = hal->rxagg_usb_timeout;
4609
rxaggcfg.threshold.size = hal->rxagg_usb_size;
4610
}
4611
break;
4612
}
4613
#endif /* CONFIG_USB_HCI */
4614
}
4615
#endif /* RTW_RX_AGGREGATION */
4616
4617
status = api->halmac_cfg_rx_aggregation(halmac, &rxaggcfg);
4618
if (status != HALMAC_RET_SUCCESS)
4619
return -1;
4620
4621
return 0;
4622
}
4623
4624
int rtw_halmac_download_rsvd_page(struct dvobj_priv *dvobj, u8 pg_offset, u8 *pbuf, u32 size)
4625
{
4626
enum halmac_ret_status status = HALMAC_RET_SUCCESS;
4627
struct halmac_adapter *halmac = dvobj_to_halmac(dvobj);
4628
struct halmac_api *api = HALMAC_GET_API(halmac);
4629
4630
status = api->halmac_dl_drv_rsvd_page(halmac, pg_offset, pbuf, size);
4631
if (status != HALMAC_RET_SUCCESS)
4632
return -1;
4633
4634
return 0;
4635
}
4636
4637
/*
4638
* Description
4639
* Fill following spec info from HALMAC API:
4640
* sec_cam_ent_num
4641
*
4642
* Return
4643
* 0 Success
4644
* others Fail
4645
*/
4646
int rtw_halmac_fill_hal_spec(struct dvobj_priv *dvobj, struct hal_spec_t *spec)
4647
{
4648
enum halmac_ret_status status;
4649
struct halmac_adapter *halmac;
4650
struct halmac_api *api;
4651
u8 cam = 0; /* Security Cam Entry Number */
4652
4653
4654
halmac = dvobj_to_halmac(dvobj);
4655
api = HALMAC_GET_API(halmac);
4656
4657
/* Prepare data from HALMAC */
4658
status = api->halmac_get_hw_value(halmac, HALMAC_HW_CAM_ENTRY_NUM, &cam);
4659
if (status != HALMAC_RET_SUCCESS)
4660
return -1;
4661
4662
/* Fill data to hal_spec_t */
4663
spec->sec_cam_ent_num = cam;
4664
4665
return 0;
4666
}
4667
4668
int rtw_halmac_p2pps(struct dvobj_priv *dvobj, struct hal_p2p_ps_para *pp2p_ps_para)
4669
{
4670
enum halmac_ret_status status = HALMAC_RET_SUCCESS;
4671
struct halmac_adapter *halmac = dvobj_to_halmac(dvobj);
4672
struct halmac_api *api = HALMAC_GET_API(halmac);
4673
struct halmac_p2pps halmac_p2p_ps;
4674
4675
(&halmac_p2p_ps)->offload_en = pp2p_ps_para->offload_en;
4676
(&halmac_p2p_ps)->role = pp2p_ps_para->role;
4677
(&halmac_p2p_ps)->ctwindow_en = pp2p_ps_para->ctwindow_en;
4678
(&halmac_p2p_ps)->noa_en = pp2p_ps_para->noa_en;
4679
(&halmac_p2p_ps)->noa_sel = pp2p_ps_para->noa_sel;
4680
(&halmac_p2p_ps)->all_sta_sleep = pp2p_ps_para->all_sta_sleep;
4681
(&halmac_p2p_ps)->discovery = pp2p_ps_para->discovery;
4682
(&halmac_p2p_ps)->disable_close_rf = pp2p_ps_para->disable_close_rf;
4683
(&halmac_p2p_ps)->p2p_port_id = _hw_port_drv2halmac(pp2p_ps_para->p2p_port_id);
4684
(&halmac_p2p_ps)->p2p_group = pp2p_ps_para->p2p_group;
4685
(&halmac_p2p_ps)->p2p_macid = pp2p_ps_para->p2p_macid;
4686
(&halmac_p2p_ps)->ctwindow_length = pp2p_ps_para->ctwindow_length;
4687
(&halmac_p2p_ps)->noa_duration_para = pp2p_ps_para->noa_duration_para;
4688
(&halmac_p2p_ps)->noa_interval_para = pp2p_ps_para->noa_interval_para;
4689
(&halmac_p2p_ps)->noa_start_time_para = pp2p_ps_para->noa_start_time_para;
4690
(&halmac_p2p_ps)->noa_count_para = pp2p_ps_para->noa_count_para;
4691
4692
status = api->halmac_p2pps(halmac, (&halmac_p2p_ps));
4693
if (status != HALMAC_RET_SUCCESS)
4694
return -1;
4695
4696
return 0;
4697
4698
}
4699
4700
/**
4701
* rtw_halmac_iqk() - Run IQ Calibration
4702
* @d: struct dvobj_priv*
4703
* @clear: IQK parameters
4704
* @segment: IQK parameters
4705
*
4706
* Process IQ Calibration(IQK).
4707
*
4708
* Return 0 for OK, otherwise fail.
4709
*/
4710
int rtw_halmac_iqk(struct dvobj_priv *d, u8 clear, u8 segment)
4711
{
4712
struct halmac_adapter *mac;
4713
struct halmac_api *api;
4714
enum halmac_ret_status status;
4715
enum halmac_feature_id id;
4716
struct halmac_iqk_para para;
4717
int ret;
4718
u8 retry = 3;
4719
u8 delay = 1; /* ms */
4720
4721
4722
mac = dvobj_to_halmac(d);
4723
api = HALMAC_GET_API(mac);
4724
id = HALMAC_FEATURE_IQK;
4725
4726
ret = init_halmac_event(d, id, NULL, 0);
4727
if (ret)
4728
return -1;
4729
4730
para.clear = clear;
4731
para.segment_iqk = segment;
4732
4733
do {
4734
status = api->halmac_start_iqk(mac, &para);
4735
if (status != HALMAC_RET_BUSY_STATE)
4736
break;
4737
RTW_WARN("%s: Fail to start IQK, status is BUSY! retry=%d\n", __FUNCTION__, retry);
4738
if (!retry)
4739
break;
4740
retry--;
4741
rtw_msleep_os(delay);
4742
} while (1);
4743
if (status != HALMAC_RET_SUCCESS) {
4744
free_halmac_event(d, id);
4745
return -1;
4746
}
4747
4748
ret = wait_halmac_event(d, id);
4749
if (ret)
4750
return -1;
4751
4752
return 0;
4753
}
4754
4755
static inline u32 _phy_parameter_val_drv2halmac(u32 val, u8 msk_en, u32 msk)
4756
{
4757
if (!msk_en)
4758
return val;
4759
4760
return (val << bitshift(msk));
4761
}
4762
4763
static int _phy_parameter_drv2halmac(struct rtw_phy_parameter *para, struct halmac_phy_parameter_info *info)
4764
{
4765
if (!para || !info)
4766
return -1;
4767
4768
_rtw_memset(info, 0, sizeof(*info));
4769
4770
switch (para->cmd) {
4771
case 0:
4772
/* MAC register */
4773
switch (para->data.mac.size) {
4774
case 1:
4775
info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W8;
4776
break;
4777
case 2:
4778
info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W16;
4779
break;
4780
default:
4781
info->cmd_id = HALMAC_PARAMETER_CMD_MAC_W32;
4782
break;
4783
}
4784
info->content.MAC_REG_W.value = _phy_parameter_val_drv2halmac(
4785
para->data.mac.value,
4786
para->data.mac.msk_en,
4787
para->data.mac.msk);
4788
info->content.MAC_REG_W.msk = para->data.mac.msk;
4789
info->content.MAC_REG_W.offset = para->data.mac.offset;
4790
info->content.MAC_REG_W.msk_en = para->data.mac.msk_en;
4791
break;
4792
4793
case 1:
4794
/* BB register */
4795
switch (para->data.bb.size) {
4796
case 1:
4797
info->cmd_id = HALMAC_PARAMETER_CMD_BB_W8;
4798
break;
4799
case 2:
4800
info->cmd_id = HALMAC_PARAMETER_CMD_BB_W16;
4801
break;
4802
default:
4803
info->cmd_id = HALMAC_PARAMETER_CMD_BB_W32;
4804
break;
4805
}
4806
info->content.BB_REG_W.value = _phy_parameter_val_drv2halmac(
4807
para->data.bb.value,
4808
para->data.bb.msk_en,
4809
para->data.bb.msk);
4810
info->content.BB_REG_W.msk = para->data.bb.msk;
4811
info->content.BB_REG_W.offset = para->data.bb.offset;
4812
info->content.BB_REG_W.msk_en = para->data.bb.msk_en;
4813
break;
4814
4815
case 2:
4816
/* RF register */
4817
info->cmd_id = HALMAC_PARAMETER_CMD_RF_W;
4818
info->content.RF_REG_W.value = _phy_parameter_val_drv2halmac(
4819
para->data.rf.value,
4820
para->data.rf.msk_en,
4821
para->data.rf.msk);
4822
info->content.RF_REG_W.msk = para->data.rf.msk;
4823
info->content.RF_REG_W.offset = para->data.rf.offset;
4824
info->content.RF_REG_W.msk_en = para->data.rf.msk_en;
4825
info->content.RF_REG_W.rf_path = para->data.rf.path;
4826
break;
4827
4828
case 3:
4829
/* Delay register */
4830
if (para->data.delay.unit == 0)
4831
info->cmd_id = HALMAC_PARAMETER_CMD_DELAY_US;
4832
else
4833
info->cmd_id = HALMAC_PARAMETER_CMD_DELAY_MS;
4834
info->content.DELAY_TIME.delay_time = para->data.delay.value;
4835
break;
4836
4837
case 0xFF:
4838
/* Latest(End) command */
4839
info->cmd_id = HALMAC_PARAMETER_CMD_END;
4840
break;
4841
4842
default:
4843
return -1;
4844
}
4845
4846
return 0;
4847
}
4848
4849
/**
4850
* rtw_halmac_cfg_phy_para() - Register(Phy parameter) configuration
4851
* @d: struct dvobj_priv*
4852
* @para: phy parameter
4853
*
4854
* Configure registers by firmware using H2C/C2H mechanism.
4855
* The latest command should be para->cmd==0xFF(End command) to finish all
4856
* processes.
4857
*
4858
* Return: 0 for OK, otherwise fail.
4859
*/
4860
int rtw_halmac_cfg_phy_para(struct dvobj_priv *d, struct rtw_phy_parameter *para)
4861
{
4862
struct halmac_adapter *mac;
4863
struct halmac_api *api;
4864
enum halmac_ret_status status;
4865
enum halmac_feature_id id;
4866
struct halmac_phy_parameter_info info;
4867
u8 full_fifo;
4868
int err, ret;
4869
4870
4871
mac = dvobj_to_halmac(d);
4872
api = HALMAC_GET_API(mac);
4873
id = HALMAC_FEATURE_CFG_PARA;
4874
full_fifo = 1; /* ToDo: How to deciede? */
4875
ret = 0;
4876
4877
err = _phy_parameter_drv2halmac(para, &info);
4878
if (err)
4879
return -1;
4880
4881
err = init_halmac_event(d, id, NULL, 0);
4882
if (err)
4883
return -1;
4884
4885
status = api->halmac_cfg_parameter(mac, &info, full_fifo);
4886
if (info.cmd_id == HALMAC_PARAMETER_CMD_END) {
4887
if (status == HALMAC_RET_SUCCESS) {
4888
err = wait_halmac_event(d, id);
4889
if (err)
4890
ret = -1;
4891
} else {
4892
free_halmac_event(d, id);
4893
ret = -1;
4894
RTW_ERR("%s: Fail to send END of cfg parameter, status is 0x%x!\n", __FUNCTION__, status);
4895
}
4896
} else {
4897
if (status == HALMAC_RET_PARA_SENDING) {
4898
err = wait_halmac_event(d, id);
4899
if (err)
4900
ret = -1;
4901
} else {
4902
free_halmac_event(d, id);
4903
if (status != HALMAC_RET_SUCCESS) {
4904
ret = -1;
4905
RTW_ERR("%s: Fail to cfg parameter, status is 0x%x!\n", __FUNCTION__, status);
4906
}
4907
}
4908
}
4909
4910
return ret;
4911
}
4912
4913
static enum halmac_wlled_mode _led_mode_drv2halmac(u8 drv_mode)
4914
{
4915
enum halmac_wlled_mode halmac_mode;
4916
4917
4918
switch (drv_mode) {
4919
case 1:
4920
halmac_mode = HALMAC_WLLED_MODE_TX;
4921
break;
4922
case 2:
4923
halmac_mode = HALMAC_WLLED_MODE_RX;
4924
break;
4925
case 3:
4926
halmac_mode = HALMAC_WLLED_MODE_SW_CTRL;
4927
break;
4928
case 0:
4929
default:
4930
halmac_mode = HALMAC_WLLED_MODE_TRX;
4931
break;
4932
}
4933
4934
return halmac_mode;
4935
}
4936
4937
/**
4938
* rtw_halmac_led_cfg() - Configure Hardware LED Mode
4939
* @d: struct dvobj_priv*
4940
* @enable: enable or disable LED function
4941
* 0: disable
4942
* 1: enable
4943
* @mode: WLan LED mode (valid when enable==1)
4944
* 0: Blink when TX(transmit packet) and RX(receive packet)
4945
* 1: Blink when TX only
4946
* 2: Blink when RX only
4947
* 3: Software control
4948
*
4949
* Configure hardware WLan LED mode.
4950
* If want to change LED mode after enabled, need to disable LED first and
4951
* enable again to set new mode.
4952
*
4953
* Return 0 for OK, otherwise fail.
4954
*/
4955
int rtw_halmac_led_cfg(struct dvobj_priv *d, u8 enable, u8 mode)
4956
{
4957
struct halmac_adapter *halmac;
4958
struct halmac_api *api;
4959
enum halmac_wlled_mode led_mode;
4960
enum halmac_ret_status status;
4961
4962
4963
halmac = dvobj_to_halmac(d);
4964
api = HALMAC_GET_API(halmac);
4965
4966
if (enable) {
4967
status = api->halmac_pinmux_set_func(halmac,
4968
HALMAC_GPIO_FUNC_WL_LED);
4969
if (status != HALMAC_RET_SUCCESS) {
4970
RTW_ERR("%s: pinmux set fail!(0x%x)\n",
4971
__FUNCTION__, status);
4972
return -1;
4973
}
4974
4975
led_mode = _led_mode_drv2halmac(mode);
4976
status = api->halmac_pinmux_wl_led_mode(halmac, led_mode);
4977
if (status != HALMAC_RET_SUCCESS) {
4978
RTW_ERR("%s: mode set fail!(0x%x)\n",
4979
__FUNCTION__, status);
4980
return -1;
4981
}
4982
} else {
4983
/* Change LED to software control and turn off */
4984
api->halmac_pinmux_wl_led_mode(halmac,
4985
HALMAC_WLLED_MODE_SW_CTRL);
4986
api->halmac_pinmux_wl_led_sw_ctrl(halmac, 0);
4987
4988
status = api->halmac_pinmux_free_func(halmac,
4989
HALMAC_GPIO_FUNC_WL_LED);
4990
if (status != HALMAC_RET_SUCCESS) {
4991
RTW_ERR("%s: pinmux free fail!(0x%x)\n",
4992
__FUNCTION__, status);
4993
return -1;
4994
}
4995
}
4996
4997
return 0;
4998
}
4999
5000
/**
5001
* rtw_halmac_led_switch() - Turn Hardware LED on/off
5002
* @d: struct dvobj_priv*
5003
* @on: LED light or not
5004
* 0: Off
5005
* 1: On(Light)
5006
*
5007
* Turn Hardware WLan LED On/Off.
5008
* Before use this function, user should call rtw_halmac_led_ctrl() to switch
5009
* mode to "software control(3)" first, otherwise control would fail.
5010
* The interval between on and off must be longer than 1 ms, or the LED would
5011
* keep light or dark only.
5012
* Ex. Turn off LED at first, turn on after 0.5ms and turn off again after
5013
* 0.5ms. The LED during this flow will only keep dark, and miss the turn on
5014
* operation between two turn off operations.
5015
*/
5016
void rtw_halmac_led_switch(struct dvobj_priv *d, u8 on)
5017
{
5018
struct halmac_adapter *halmac;
5019
struct halmac_api *api;
5020
5021
5022
halmac = dvobj_to_halmac(d);
5023
api = HALMAC_GET_API(halmac);
5024
5025
api->halmac_pinmux_wl_led_sw_ctrl(halmac, on);
5026
}
5027
5028
/**
5029
* rtw_halmac_bt_wake_cfg() - Configure BT wake host function
5030
* @d: struct dvobj_priv*
5031
* @enable: enable or disable BT wake host function
5032
* 0: disable
5033
* 1: enable
5034
*
5035
* Configure pinmux to allow BT to control BT wake host pin.
5036
*
5037
* Return 0 for OK, otherwise fail.
5038
*/
5039
int rtw_halmac_bt_wake_cfg(struct dvobj_priv *d, u8 enable)
5040
{
5041
struct halmac_adapter *halmac;
5042
struct halmac_api *api;
5043
enum halmac_ret_status status;
5044
5045
5046
halmac = dvobj_to_halmac(d);
5047
api = HALMAC_GET_API(halmac);
5048
5049
if (enable) {
5050
status = api->halmac_pinmux_set_func(halmac,
5051
HALMAC_GPIO_FUNC_BT_HOST_WAKE1);
5052
if (status != HALMAC_RET_SUCCESS) {
5053
RTW_ERR("%s: pinmux set BT_HOST_WAKE1 fail!(0x%x)\n",
5054
__FUNCTION__, status);
5055
return -1;
5056
}
5057
} else {
5058
status = api->halmac_pinmux_free_func(halmac,
5059
HALMAC_GPIO_FUNC_BT_HOST_WAKE1);
5060
if (status != HALMAC_RET_SUCCESS) {
5061
RTW_ERR("%s: pinmux free BT_HOST_WAKE1 fail!(0x%x)\n",
5062
__FUNCTION__, status);
5063
return -1;
5064
}
5065
}
5066
5067
return 0;
5068
}
5069
5070
#ifdef CONFIG_PNO_SUPPORT
5071
/**
5072
* _halmac_scanoffload() - Switch channel by firmware during scanning
5073
* @d: struct dvobj_priv*
5074
* @enable: 1: enable, 0: disable
5075
* @nlo: 1: nlo mode (no c2h event), 0: normal mode
5076
* @ssid: ssid of probe request
5077
* @ssid_len: ssid length
5078
*
5079
* Switch Channel and Send Porbe Request Offloaded by FW
5080
*
5081
* Return 0 for OK, otherwise fail.
5082
*/
5083
static int _halmac_scanoffload(struct dvobj_priv *d, u32 enable, u8 nlo,
5084
u8 *ssid, u8 ssid_len)
5085
{
5086
struct _ADAPTER *adapter;
5087
struct halmac_adapter *mac;
5088
struct halmac_api *api;
5089
enum halmac_ret_status status;
5090
struct halmac_ch_info ch_info;
5091
struct halmac_ch_switch_option cs_option;
5092
struct mlme_ext_priv *pmlmeext;
5093
enum halmac_feature_id id_update, id_ch_sw;
5094
struct halmac_indicator *indicator, *tbl;
5095
5096
int err = 0;
5097
u8 probereq[64];
5098
u32 len = 0;
5099
int i = 0;
5100
struct pno_ssid pnossid;
5101
struct rf_ctl_t *rfctl = NULL;
5102
struct _RT_CHANNEL_INFO *ch_set;
5103
5104
5105
tbl = d->hmpriv.indicator;
5106
adapter = dvobj_get_primary_adapter(d);
5107
mac = dvobj_to_halmac(d);
5108
if (!mac)
5109
return -1;
5110
api = HALMAC_GET_API(mac);
5111
id_update = HALMAC_FEATURE_UPDATE_PACKET;
5112
id_ch_sw = HALMAC_FEATURE_CHANNEL_SWITCH;
5113
pmlmeext = &(adapter->mlmeextpriv);
5114
rfctl = adapter_to_rfctl(adapter);
5115
ch_set = rfctl->channel_set;
5116
5117
RTW_INFO("%s: %s scanoffload, mode: %s\n",
5118
__FUNCTION__, enable?"Enable":"Disable",
5119
nlo?"PNO/NLO":"Normal");
5120
5121
if (enable) {
5122
_rtw_memset(probereq, 0, sizeof(probereq));
5123
5124
_rtw_memset(&pnossid, 0, sizeof(pnossid));
5125
if (ssid) {
5126
if (ssid_len > sizeof(pnossid.SSID)) {
5127
RTW_ERR("%s: SSID length(%d) is too long(>%d)!!\n",
5128
__FUNCTION__, ssid_len, sizeof(pnossid.SSID));
5129
return -1;
5130
}
5131
5132
pnossid.SSID_len = ssid_len;
5133
_rtw_memcpy(pnossid.SSID, ssid, ssid_len);
5134
}
5135
5136
rtw_hal_construct_ProbeReq(adapter, probereq, &len, &pnossid);
5137
5138
if (!nlo) {
5139
err = init_halmac_event(d, id_update, NULL, 0);
5140
if (err)
5141
return -1;
5142
}
5143
5144
status = api->halmac_update_packet(mac, HALMAC_PACKET_PROBE_REQ,
5145
probereq, len);
5146
if (status != HALMAC_RET_SUCCESS) {
5147
if (!nlo)
5148
free_halmac_event(d, id_update);
5149
RTW_ERR("%s: halmac_update_packet FAIL(%d)!!\n",
5150
__FUNCTION__, status);
5151
return -1;
5152
}
5153
5154
if (!nlo) {
5155
err = wait_halmac_event(d, id_update);
5156
if (err)
5157
RTW_ERR("%s: wait update packet FAIL(%d)!!\n",
5158
__FUNCTION__, err);
5159
}
5160
5161
api->halmac_clear_ch_info(mac);
5162
5163
for (i = 0; i < rfctl->max_chan_nums && ch_set[i].ChannelNum != 0; i++) {
5164
_rtw_memset(&ch_info, 0, sizeof(ch_info));
5165
ch_info.extra_info = 0;
5166
ch_info.channel = ch_set[i].ChannelNum;
5167
ch_info.bw = HALMAC_BW_20;
5168
ch_info.pri_ch_idx = HALMAC_CH_IDX_1;
5169
ch_info.action_id = HALMAC_CS_ACTIVE_SCAN;
5170
ch_info.timeout = 1;
5171
status = api->halmac_add_ch_info(mac, &ch_info);
5172
if (status != HALMAC_RET_SUCCESS) {
5173
RTW_ERR("%s: add_ch_info FAIL(%d)!!\n",
5174
__FUNCTION__, status);
5175
return -1;
5176
}
5177
}
5178
5179
/* set channel switch option */
5180
_rtw_memset(&cs_option, 0, sizeof(cs_option));
5181
cs_option.dest_bw = HALMAC_BW_20;
5182
cs_option.periodic_option = HALMAC_CS_PERIODIC_2_PHASE;
5183
cs_option.dest_pri_ch_idx = HALMAC_CH_IDX_UNDEFINE;
5184
cs_option.tsf_low = 0;
5185
cs_option.switch_en = 1;
5186
cs_option.dest_ch_en = 1;
5187
cs_option.absolute_time_en = 0;
5188
cs_option.dest_ch = 1;
5189
5190
cs_option.normal_period = 5;
5191
cs_option.normal_period_sel = 0;
5192
cs_option.normal_cycle = 10;
5193
5194
cs_option.phase_2_period = 1;
5195
cs_option.phase_2_period_sel = 1;
5196
5197
/* nlo is for wow fw, 1: no c2h response */
5198
cs_option.nlo_en = nlo;
5199
5200
if (!nlo) {
5201
err = init_halmac_event(d, id_ch_sw, NULL, 0);
5202
if (err)
5203
return -1;
5204
}
5205
5206
status = api->halmac_ctrl_ch_switch(mac, &cs_option);
5207
if (status != HALMAC_RET_SUCCESS) {
5208
if (!nlo)
5209
free_halmac_event(d, id_ch_sw);
5210
RTW_ERR("%s: halmac_ctrl_ch_switch FAIL(%d)!!\n",
5211
__FUNCTION__, status);
5212
return -1;
5213
}
5214
5215
if (!nlo) {
5216
err = wait_halmac_event(d, id_ch_sw);
5217
if (err)
5218
RTW_ERR("%s: wait ctrl_ch_switch FAIL(%d)!!\n",
5219
__FUNCTION__, err);
5220
}
5221
} else {
5222
api->halmac_clear_ch_info(mac);
5223
5224
_rtw_memset(&cs_option, 0, sizeof(cs_option));
5225
cs_option.switch_en = 0;
5226
5227
if (!nlo) {
5228
err = init_halmac_event(d, id_ch_sw, NULL, 0);
5229
if (err)
5230
return -1;
5231
}
5232
5233
status = api->halmac_ctrl_ch_switch(mac, &cs_option);
5234
if (status != HALMAC_RET_SUCCESS) {
5235
if (!nlo)
5236
free_halmac_event(d, id_ch_sw);
5237
RTW_ERR("%s: halmac_ctrl_ch_switch FAIL(%d)!!\n",
5238
__FUNCTION__, status);
5239
return -1;
5240
}
5241
5242
if (!nlo) {
5243
err = wait_halmac_event(d, id_ch_sw);
5244
if (err)
5245
RTW_ERR("%s: wait ctrl_ch_switch FAIL(%d)!!\n",
5246
__FUNCTION__, err);
5247
}
5248
}
5249
5250
return 0;
5251
}
5252
5253
/**
5254
* rtw_halmac_pno_scanoffload() - Control firmware scan AP function for PNO
5255
* @d: struct dvobj_priv*
5256
* @enable: 1: enable, 0: disable
5257
*
5258
* Switch firmware scan AP function for PNO(prefer network offload) or
5259
* NLO(network list offload).
5260
*
5261
* Return 0 for OK, otherwise fail.
5262
*/
5263
int rtw_halmac_pno_scanoffload(struct dvobj_priv *d, u32 enable)
5264
{
5265
return _halmac_scanoffload(d, enable, 1, NULL, 0);
5266
}
5267
#endif /* CONFIG_PNO_SUPPORT */
5268
5269
#ifdef CONFIG_SDIO_HCI
5270
5271
/*
5272
* Description:
5273
* Update queue allocated page number to driver
5274
*
5275
* Parameter:
5276
* d pointer to struct dvobj_priv of driver
5277
*
5278
* Return:
5279
* 0 Success, "page" is valid.
5280
* others Fail, "page" is invalid.
5281
*/
5282
int rtw_halmac_query_tx_page_num(struct dvobj_priv *d)
5283
{
5284
PADAPTER adapter;
5285
struct halmacpriv *hmpriv;
5286
struct halmac_adapter *halmac;
5287
struct halmac_api *api;
5288
struct halmac_rqpn_map rqpn;
5289
enum halmac_dma_mapping dmaqueue;
5290
struct halmac_txff_allocation fifosize;
5291
enum halmac_ret_status status;
5292
u8 i;
5293
5294
5295
adapter = dvobj_get_primary_adapter(d);
5296
hmpriv = &d->hmpriv;
5297
halmac = dvobj_to_halmac(d);
5298
api = HALMAC_GET_API(halmac);
5299
_rtw_memset((void *)&rqpn, 0, sizeof(rqpn));
5300
_rtw_memset((void *)&fifosize, 0, sizeof(fifosize));
5301
5302
status = api->halmac_get_hw_value(halmac, HALMAC_HW_RQPN_MAPPING, &rqpn);
5303
if (status != HALMAC_RET_SUCCESS)
5304
return -1;
5305
status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFF_ALLOCATION, &fifosize);
5306
if (status != HALMAC_RET_SUCCESS)
5307
return -1;
5308
5309
for (i = 0; i < HW_QUEUE_ENTRY; i++) {
5310
hmpriv->txpage[i] = 0;
5311
5312
/* Driver index mapping to HALMAC DMA queue */
5313
dmaqueue = HALMAC_DMA_MAPPING_UNDEFINE;
5314
switch (i) {
5315
case VO_QUEUE_INX:
5316
dmaqueue = rqpn.dma_map_vo;
5317
break;
5318
case VI_QUEUE_INX:
5319
dmaqueue = rqpn.dma_map_vi;
5320
break;
5321
case BE_QUEUE_INX:
5322
dmaqueue = rqpn.dma_map_be;
5323
break;
5324
case BK_QUEUE_INX:
5325
dmaqueue = rqpn.dma_map_bk;
5326
break;
5327
case MGT_QUEUE_INX:
5328
dmaqueue = rqpn.dma_map_mg;
5329
break;
5330
case HIGH_QUEUE_INX:
5331
dmaqueue = rqpn.dma_map_hi;
5332
break;
5333
case BCN_QUEUE_INX:
5334
case TXCMD_QUEUE_INX:
5335
/* Unlimited */
5336
hmpriv->txpage[i] = 0xFFFF;
5337
continue;
5338
}
5339
5340
switch (dmaqueue) {
5341
case HALMAC_DMA_MAPPING_EXTRA:
5342
hmpriv->txpage[i] = fifosize.extra_queue_pg_num;
5343
break;
5344
case HALMAC_DMA_MAPPING_LOW:
5345
hmpriv->txpage[i] = fifosize.low_queue_pg_num;
5346
break;
5347
case HALMAC_DMA_MAPPING_NORMAL:
5348
hmpriv->txpage[i] = fifosize.normal_queue_pg_num;
5349
break;
5350
case HALMAC_DMA_MAPPING_HIGH:
5351
hmpriv->txpage[i] = fifosize.high_queue_pg_num;
5352
break;
5353
case HALMAC_DMA_MAPPING_UNDEFINE:
5354
break;
5355
}
5356
hmpriv->txpage[i] += fifosize.pub_queue_pg_num;
5357
}
5358
5359
return 0;
5360
}
5361
5362
/*
5363
* Description:
5364
* Get specific queue allocated page number
5365
*
5366
* Parameter:
5367
* d pointer to struct dvobj_priv of driver
5368
* queue target queue to query, VO/VI/BE/BK/.../TXCMD_QUEUE_INX
5369
* page return allocated page number
5370
*
5371
* Return:
5372
* 0 Success, "page" is valid.
5373
* others Fail, "page" is invalid.
5374
*/
5375
int rtw_halmac_get_tx_queue_page_num(struct dvobj_priv *d, u8 queue, u32 *page)
5376
{
5377
*page = 0;
5378
if (queue < HW_QUEUE_ENTRY)
5379
*page = d->hmpriv.txpage[queue];
5380
5381
return 0;
5382
}
5383
5384
/*
5385
* Return:
5386
* address for SDIO command
5387
*/
5388
u32 rtw_halmac_sdio_get_tx_addr(struct dvobj_priv *d, u8 *desc, u32 size)
5389
{
5390
struct halmac_adapter *mac;
5391
struct halmac_api *api;
5392
enum halmac_ret_status status;
5393
u32 addr;
5394
5395
5396
mac = dvobj_to_halmac(d);
5397
api = HALMAC_GET_API(mac);
5398
5399
status = api->halmac_get_sdio_tx_addr(mac, desc, size, &addr);
5400
if (HALMAC_RET_SUCCESS != status)
5401
return 0;
5402
5403
return addr;
5404
}
5405
5406
int rtw_halmac_sdio_tx_allowed(struct dvobj_priv *d, u8 *buf, u32 size)
5407
{
5408
struct halmac_adapter *mac;
5409
struct halmac_api *api;
5410
enum halmac_ret_status status;
5411
5412
5413
mac = dvobj_to_halmac(d);
5414
api = HALMAC_GET_API(mac);
5415
5416
status = api->halmac_tx_allowed_sdio(mac, buf, size);
5417
if (HALMAC_RET_SUCCESS != status)
5418
return -1;
5419
5420
return 0;
5421
}
5422
5423
u32 rtw_halmac_sdio_get_rx_addr(struct dvobj_priv *d, u8 *seq)
5424
{
5425
u8 id;
5426
5427
#define RTW_SDIO_ADDR_RX_RX0FF_PRFIX 0x0E000
5428
#define RTW_SDIO_ADDR_RX_RX0FF_GEN(a) (RTW_SDIO_ADDR_RX_RX0FF_PRFIX|(a&0x3))
5429
5430
id = *seq;
5431
(*seq)++;
5432
return RTW_SDIO_ADDR_RX_RX0FF_GEN(id);
5433
}
5434
5435
int rtw_halmac_sdio_set_tx_format(struct dvobj_priv *d, enum halmac_sdio_tx_format format)
5436
{
5437
struct halmac_adapter *mac;
5438
struct halmac_api *api;
5439
enum halmac_ret_status status;
5440
5441
mac = dvobj_to_halmac(d);
5442
api = HALMAC_GET_API(mac);
5443
5444
status = api->halmac_set_hw_value(mac, HALMAC_HW_SDIO_TX_FORMAT, &format);
5445
if (HALMAC_RET_SUCCESS != status)
5446
return -1;
5447
5448
return 0;
5449
}
5450
#endif /* CONFIG_SDIO_HCI */
5451
5452
#ifdef CONFIG_USB_HCI
5453
u8 rtw_halmac_usb_get_bulkout_id(struct dvobj_priv *d, u8 *buf, u32 size)
5454
{
5455
struct halmac_adapter *mac;
5456
struct halmac_api *api;
5457
enum halmac_ret_status status;
5458
u8 bulkout_id;
5459
5460
5461
mac = dvobj_to_halmac(d);
5462
api = HALMAC_GET_API(mac);
5463
5464
status = api->halmac_get_usb_bulkout_id(mac, buf, size, &bulkout_id);
5465
if (HALMAC_RET_SUCCESS != status)
5466
return 0;
5467
5468
return bulkout_id;
5469
}
5470
5471
/**
5472
* rtw_halmac_usb_get_txagg_desc_num() - MAX descriptor number in one bulk for TX
5473
* @d: struct dvobj_priv*
5474
* @size: TX FIFO size, unit is byte.
5475
*
5476
* Get MAX descriptor number in one bulk out from HALMAC.
5477
*
5478
* Return 0 for OK, otherwise fail.
5479
*/
5480
int rtw_halmac_usb_get_txagg_desc_num(struct dvobj_priv *d, u8 *num)
5481
{
5482
struct halmac_adapter *halmac;
5483
struct halmac_api *api;
5484
enum halmac_ret_status status;
5485
u8 val = 0;
5486
5487
5488
halmac = dvobj_to_halmac(d);
5489
api = HALMAC_GET_API(halmac);
5490
5491
status = api->halmac_get_hw_value(halmac, HALMAC_HW_USB_TXAGG_DESC_NUM, &val);
5492
if (status != HALMAC_RET_SUCCESS)
5493
return -1;
5494
5495
*num = val;
5496
5497
return 0;
5498
}
5499
5500
static inline enum halmac_usb_mode _usb_mode_drv2halmac(enum RTW_USB_SPEED usb_mode)
5501
{
5502
enum halmac_usb_mode halmac_usb_mode = HALMAC_USB_MODE_U2;
5503
5504
switch (usb_mode) {
5505
case RTW_USB_SPEED_2:
5506
halmac_usb_mode = HALMAC_USB_MODE_U2;
5507
break;
5508
case RTW_USB_SPEED_3:
5509
halmac_usb_mode = HALMAC_USB_MODE_U3;
5510
break;
5511
default:
5512
halmac_usb_mode = HALMAC_USB_MODE_U2;
5513
break;
5514
}
5515
5516
return halmac_usb_mode;
5517
}
5518
5519
u8 rtw_halmac_switch_usb_mode(struct dvobj_priv *d, enum RTW_USB_SPEED usb_mode)
5520
{
5521
PADAPTER adapter;
5522
struct halmac_adapter *mac;
5523
struct halmac_api *api;
5524
enum halmac_ret_status status;
5525
enum halmac_usb_mode halmac_usb_mode;
5526
5527
adapter = dvobj_get_primary_adapter(d);
5528
mac = dvobj_to_halmac(d);
5529
api = HALMAC_GET_API(mac);
5530
halmac_usb_mode = _usb_mode_drv2halmac(usb_mode);
5531
status = api->halmac_set_hw_value(mac, HALMAC_HW_USB_MODE, (void *)&halmac_usb_mode);
5532
5533
if (HALMAC_RET_SUCCESS != status)
5534
return _FAIL;
5535
5536
return _SUCCESS;
5537
}
5538
#endif /* CONFIG_USB_HCI */
5539
5540
#ifdef CONFIG_BEAMFORMING
5541
#ifdef RTW_BEAMFORMING_VERSION_2
5542
int rtw_halmac_bf_add_mu_bfer(struct dvobj_priv *d, u16 paid, u16 csi_para,
5543
u16 my_aid, enum halmac_csi_seg_len sel, u8 *addr)
5544
{
5545
struct halmac_adapter *mac;
5546
struct halmac_api *api;
5547
enum halmac_ret_status status;
5548
struct halmac_mu_bfer_init_para param;
5549
5550
5551
mac = dvobj_to_halmac(d);
5552
api = HALMAC_GET_API(mac);
5553
5554
_rtw_memset(&param, 0, sizeof(param));
5555
param.paid = paid;
5556
param.csi_para = csi_para;
5557
param.my_aid = my_aid;
5558
param.csi_length_sel = sel;
5559
_rtw_memcpy(param.bfer_address.addr, addr, 6);
5560
5561
status = api->halmac_mu_bfer_entry_init(mac, &param);
5562
if (status != HALMAC_RET_SUCCESS)
5563
return -1;
5564
5565
return 0;
5566
}
5567
5568
int rtw_halmac_bf_del_mu_bfer(struct dvobj_priv *d)
5569
{
5570
struct halmac_adapter *mac;
5571
struct halmac_api *api;
5572
enum halmac_ret_status status;
5573
5574
5575
mac = dvobj_to_halmac(d);
5576
api = HALMAC_GET_API(mac);
5577
5578
status = api->halmac_mu_bfer_entry_del(mac);
5579
if (status != HALMAC_RET_SUCCESS)
5580
return -1;
5581
5582
return 0;
5583
}
5584
5585
5586
int rtw_halmac_bf_cfg_sounding(struct dvobj_priv *d,
5587
enum halmac_snd_role role, enum halmac_data_rate rate)
5588
{
5589
struct halmac_adapter *mac;
5590
struct halmac_api *api;
5591
enum halmac_ret_status status;
5592
5593
5594
mac = dvobj_to_halmac(d);
5595
api = HALMAC_GET_API(mac);
5596
5597
status = api->halmac_cfg_sounding(mac, role, rate);
5598
if (status != HALMAC_RET_SUCCESS)
5599
return -1;
5600
5601
return 0;
5602
}
5603
5604
int rtw_halmac_bf_del_sounding(struct dvobj_priv *d,
5605
enum halmac_snd_role role)
5606
{
5607
struct halmac_adapter *mac;
5608
struct halmac_api *api;
5609
enum halmac_ret_status status;
5610
5611
5612
mac = dvobj_to_halmac(d);
5613
api = HALMAC_GET_API(mac);
5614
5615
status = api->halmac_del_sounding(mac, role);
5616
if (status != HALMAC_RET_SUCCESS)
5617
return -1;
5618
5619
return 0;
5620
}
5621
5622
/**
5623
* rtw_halmac_bf_cfg_csi_rate() - Config data rate for CSI report frame by RSSI
5624
* @d: struct dvobj_priv*
5625
* @rssi: RSSI vlaue, unit is percentage (0~100).
5626
* @current_rate: Current CSI frame rate
5627
* Valid value example
5628
* 0 CCK 1M
5629
* 3 CCK 11M
5630
* 4 OFDM 6M
5631
* and so on
5632
* @fixrate_en: Enable to fix CSI frame in VHT rate, otherwise legacy OFDM rate.
5633
* The value "0" for disable, otheriwse enable.
5634
* @new_rate: Return new data rate, and value range is the same as
5635
* current_rate
5636
* @bmp_ofdm54: Return to suggest enabling OFDM 54M for CSI report frame or not,
5637
* The valid values and meanings are:
5638
* 0x00 disable
5639
* 0x01 enable
5640
* 0xFF Keep current setting
5641
*
5642
* According RSSI to config data rate for CSI report frame of Beamforming.
5643
*
5644
* Return 0 for OK, otherwise fail.
5645
*/
5646
int rtw_halmac_bf_cfg_csi_rate(struct dvobj_priv *d, u8 rssi,
5647
u8 current_rate, u8 fixrate_en, u8 *new_rate,
5648
u8 *bmp_ofdm54)
5649
{
5650
struct halmac_adapter *mac;
5651
struct halmac_api *api;
5652
enum halmac_ret_status status;
5653
5654
5655
mac = dvobj_to_halmac(d);
5656
api = HALMAC_GET_API(mac);
5657
5658
status = api->halmac_cfg_csi_rate(mac,
5659
rssi, current_rate, fixrate_en, new_rate,
5660
bmp_ofdm54);
5661
if (status != HALMAC_RET_SUCCESS)
5662
return -1;
5663
5664
return 0;
5665
}
5666
5667
int rtw_halmac_bf_cfg_mu_mimo(struct dvobj_priv *d, enum halmac_snd_role role,
5668
u8 *sounding_sts, u16 grouping_bitmap, u8 mu_tx_en,
5669
u32 *given_gid_tab, u32 *given_user_pos)
5670
{
5671
struct halmac_adapter *mac;
5672
struct halmac_api *api;
5673
enum halmac_ret_status status;
5674
struct halmac_cfg_mumimo_para param;
5675
5676
5677
mac = dvobj_to_halmac(d);
5678
api = HALMAC_GET_API(mac);
5679
5680
_rtw_memset(&param, 0, sizeof(param));
5681
5682
param.role = role;
5683
param.grouping_bitmap = grouping_bitmap;
5684
param.mu_tx_en = mu_tx_en;
5685
5686
if (sounding_sts)
5687
_rtw_memcpy(param.sounding_sts, sounding_sts, 6);
5688
5689
if (given_gid_tab)
5690
_rtw_memcpy(param.given_gid_tab, given_gid_tab, 8);
5691
5692
if (given_user_pos)
5693
_rtw_memcpy(param.given_user_pos, given_user_pos, 16);
5694
5695
status = api->halmac_cfg_mumimo(mac, &param);
5696
if (status != HALMAC_RET_SUCCESS)
5697
return -1;
5698
5699
return 0;
5700
}
5701
5702
#endif /* RTW_BEAMFORMING_VERSION_2 */
5703
#endif /* CONFIG_BEAMFORMING */
5704
5705